summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-06-19 06:22:23 -0400
committerGitHub <noreply@github.com>2025-06-19 12:22:23 +0200
commit56f468681aaedefcdada1b86c441c12ae96e7fea (patch)
tree5203a04706794d2da757e835c926ce377a6882d1 /django
parentbc1bfe12b613334bd625aeb36fd44af96d186c10 (diff)
Refs #35038 -- Reduced CreateModel/AlterConstraint operations when optimizing migrations.
Diffstat (limited to 'django')
-rw-r--r--django/db/migrations/operations/models.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index 93d5629ebe..1b241230df 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -346,6 +346,21 @@ class CreateModel(ModelOperation):
},
),
]
+ elif isinstance(operation, AlterConstraint):
+ options_constraints = [
+ constraint
+ for constraint in self.options.get("constraints", [])
+ if constraint.name != operation.name
+ ] + [operation.constraint]
+ return [
+ replace(
+ self,
+ options={
+ **self.options,
+ "constraints": options_constraints,
+ },
+ ),
+ ]
elif isinstance(operation, RemoveConstraint):
options_constraints = [
constraint