summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2022-01-04 06:24:03 +0100
committerGitHub <noreply@github.com>2022-01-04 06:24:03 +0100
commit482ee63b6f320cd4a834cb46fc651877bd2f2e28 (patch)
treecbc8b5a781f0075deb7aebe87189435e715372e4 /django
parent0ed2919814c80e31626dffdb6b80d0c20d43452f (diff)
Fixed #33402 -- Optimized multiple AlterFooTogether operations.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/operations/models.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index c120f5d32d..01c44a9a26 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -34,9 +34,12 @@ class ModelOperation(Operation):
def reduce(self, operation, app_label):
return (
super().reduce(operation, app_label) or
- not operation.references_model(self.name, app_label)
+ self.can_reduce_through(operation, app_label)
)
+ def can_reduce_through(self, operation, app_label):
+ return not operation.references_model(self.name, app_label)
+
class CreateModel(ModelOperation):
"""Create a model's table."""
@@ -528,6 +531,14 @@ class AlterTogetherOptionOperation(ModelOptionOperation):
def migration_name_fragment(self):
return 'alter_%s_%s' % (self.name_lower, self.option_name)
+ def can_reduce_through(self, operation, app_label):
+ return (
+ super().can_reduce_through(operation, app_label) or (
+ isinstance(operation, AlterTogetherOptionOperation) and
+ type(operation) is not type(self)
+ )
+ )
+
class AlterUniqueTogether(AlterTogetherOptionOperation):
"""