mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Refs #34534 -- Reduced constraint operations with Meta.constraints when optimizing migrations.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9c5e382b98
commit
8b7ddd1b62
@@ -342,6 +342,40 @@ class CreateModel(ModelOperation):
|
||||
managers=self.managers,
|
||||
),
|
||||
]
|
||||
elif isinstance(operation, AddConstraint):
|
||||
return [
|
||||
CreateModel(
|
||||
self.name,
|
||||
fields=self.fields,
|
||||
options={
|
||||
**self.options,
|
||||
"constraints": [
|
||||
*self.options.get("constraints", []),
|
||||
operation.constraint,
|
||||
],
|
||||
},
|
||||
bases=self.bases,
|
||||
managers=self.managers,
|
||||
),
|
||||
]
|
||||
elif isinstance(operation, RemoveConstraint):
|
||||
options_constraints = [
|
||||
constraint
|
||||
for constraint in self.options.get("constraints", [])
|
||||
if constraint.name != operation.name
|
||||
]
|
||||
return [
|
||||
CreateModel(
|
||||
self.name,
|
||||
fields=self.fields,
|
||||
options={
|
||||
**self.options,
|
||||
"constraints": options_constraints,
|
||||
},
|
||||
bases=self.bases,
|
||||
managers=self.managers,
|
||||
),
|
||||
]
|
||||
return super().reduce(operation, app_label)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user