mirror of https://github.com/django/django.git
Fixed #27717 -- Allowed migration optimization across AlterModelOptions.
This commit is contained in:
parent
6872ce2266
commit
7156a6c9c4
|
@ -151,6 +151,18 @@ class CreateModel(ModelOperation):
|
||||||
managers=self.managers,
|
managers=self.managers,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
elif isinstance(operation, AlterModelOptions) and self.name_lower == operation.name_lower:
|
||||||
|
new_options = self.options.copy()
|
||||||
|
new_options.update(operation.options)
|
||||||
|
return [
|
||||||
|
CreateModel(
|
||||||
|
self.name,
|
||||||
|
fields=self.fields,
|
||||||
|
options=new_options,
|
||||||
|
bases=self.bases,
|
||||||
|
managers=self.managers,
|
||||||
|
),
|
||||||
|
]
|
||||||
elif isinstance(operation, FieldOperation) and self.name_lower == operation.model_name_lower:
|
elif isinstance(operation, FieldOperation) and self.name_lower == operation.model_name_lower:
|
||||||
if isinstance(operation, AddField):
|
if isinstance(operation, AddField):
|
||||||
# Don't allow optimizations of FKs through models they reference
|
# Don't allow optimizations of FKs through models they reference
|
||||||
|
|
|
@ -101,6 +101,17 @@ class OptimizerTests(SimpleTestCase):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_create_alter_model_options(self):
|
||||||
|
self.assertOptimizesTo(
|
||||||
|
[
|
||||||
|
migrations.CreateModel('Foo', fields=[]),
|
||||||
|
migrations.AlterModelOptions(name='Foo', options={'verbose_name_plural': 'Foozes'}),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
migrations.CreateModel('Foo', fields=[], options={'verbose_name_plural': 'Foozes'}),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
def _test_create_alter_foo_delete_model(self, alter_foo):
|
def _test_create_alter_foo_delete_model(self, alter_foo):
|
||||||
"""
|
"""
|
||||||
CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/
|
CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/
|
||||||
|
|
Loading…
Reference in New Issue