Kaydet (Commit) 7156a6c9 authored tarafından Ed Morley's avatar Ed Morley Kaydeden (comit) Tim Graham

Fixed #27717 -- Allowed migration optimization across AlterModelOptions.

üst 6872ce22
......@@ -151,6 +151,18 @@ class CreateModel(ModelOperation):
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:
if isinstance(operation, AddField):
# 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):
"""
CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment