Fixed #32262 -- Fixed migration optimization for model creation and Meta options removal.
This commit is contained in:
parent
bb64b99b78
commit
8d582bf510
|
@ -137,11 +137,15 @@ class CreateModel(ModelOperation):
|
|||
),
|
||||
]
|
||||
elif isinstance(operation, AlterModelOptions) and self.name_lower == operation.name_lower:
|
||||
options = {**self.options, **operation.options}
|
||||
for key in operation.ALTER_OPTION_KEYS:
|
||||
if key not in operation.options:
|
||||
options.pop(key, None)
|
||||
return [
|
||||
CreateModel(
|
||||
self.name,
|
||||
fields=self.fields,
|
||||
options={**self.options, **operation.options},
|
||||
options=options,
|
||||
bases=self.bases,
|
||||
managers=self.managers,
|
||||
),
|
||||
|
|
|
@ -119,6 +119,42 @@ class OptimizerTests(SimpleTestCase):
|
|||
]
|
||||
)
|
||||
|
||||
def test_create_model_and_remove_model_options(self):
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel(
|
||||
'MyModel',
|
||||
fields=[],
|
||||
options={'verbose_name': 'My Model'},
|
||||
),
|
||||
migrations.AlterModelOptions('MyModel', options={}),
|
||||
],
|
||||
[migrations.CreateModel('MyModel', fields=[])],
|
||||
)
|
||||
self.assertOptimizesTo(
|
||||
[
|
||||
migrations.CreateModel(
|
||||
'MyModel',
|
||||
fields=[],
|
||||
options={
|
||||
'verbose_name': 'My Model',
|
||||
'verbose_name_plural': 'My Model plural',
|
||||
},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
'MyModel',
|
||||
options={'verbose_name': 'My Model'},
|
||||
),
|
||||
],
|
||||
[
|
||||
migrations.CreateModel(
|
||||
'MyModel',
|
||||
fields=[],
|
||||
options={'verbose_name': 'My Model'},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def _test_create_alter_foo_delete_model(self, alter_foo):
|
||||
"""
|
||||
CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/
|
||||
|
|
Loading…
Reference in New Issue