diff options
Diffstat (limited to 'django')
-rw-r--r-- | django/db/migrations/operations/models.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index 9c5bd5fbcb..b18ef55369 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -929,6 +929,9 @@ class AddIndex(IndexOperation): def reduce(self, operation, app_label): if isinstance(operation, RemoveIndex) and self.index.name == operation.name: return [] + if isinstance(operation, RenameIndex) and self.index.name == operation.old_name: + self.index.name = operation.new_name + return [AddIndex(model_name=self.model_name, index=self.index)] return super().reduce(operation, app_label) @@ -1164,6 +1167,15 @@ class AddConstraint(IndexOperation): def migration_name_fragment(self): return "%s_%s" % (self.model_name_lower, self.constraint.name.lower()) + def reduce(self, operation, app_label): + if ( + isinstance(operation, RemoveConstraint) + and self.model_name_lower == operation.model_name_lower + and self.constraint.name == operation.name + ): + return [] + return super().reduce(operation, app_label) + class RemoveConstraint(IndexOperation): option_name = "constraints" |