From 482ee63b6f320cd4a834cb46fc651877bd2f2e28 Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Tue, 4 Jan 2022 06:24:03 +0100 Subject: Fixed #33402 -- Optimized multiple AlterFooTogether operations. --- django/db/migrations/operations/models.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'django') 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): """ -- cgit v1.3