1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #32256 -- Fixed migration optimization crash when swapping field names.

This disables optimization of RenameField operation when an old field
name is referenced in subsequent operations.

Co-authored-by: InvalidInterrupt <InvalidInterrupt@users.noreply.github.com>
This commit is contained in:
Hasan Ramezani
2020-12-13 22:41:20 +01:00
committed by Mariusz Felisiak
parent ab58f07250
commit 7c18b22e2f
2 changed files with 22 additions and 2 deletions

View File

@@ -572,6 +572,23 @@ class OptimizerTests(SimpleTestCase):
],
)
def test_swapping_fields_names(self):
self.assertDoesNotOptimize(
[
migrations.CreateModel(
'MyModel',
[
('field_a', models.IntegerField()),
('field_b', models.IntegerField()),
],
),
migrations.RunPython(migrations.RunPython.noop),
migrations.RenameField('MyModel', 'field_a', 'field_c'),
migrations.RenameField('MyModel', 'field_b', 'field_a'),
migrations.RenameField('MyModel', 'field_c', 'field_b'),
],
)
def test_create_model_remove_field(self):
"""
RemoveField should optimize into CreateModel.