diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-08-04 11:58:44 +1000 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-08-04 11:59:48 +1000 |
| commit | a918c60c378b575ca52ebcfae977056b8bc5a4de (patch) | |
| tree | 6ca3ec8882bea8a286cdc4726283a031ea31dde1 /tests/migrations | |
| parent | 99f3a65c730f643d35d959aa9a693101b2d21efd (diff) | |
[1.7.x] Fixed #23091: CreateModel and AddField were clashing with deferred SQL
Diffstat (limited to 'tests/migrations')
| -rw-r--r-- | tests/migrations/test_operations.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index cbcc2babbe..518334afa1 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -1051,6 +1051,33 @@ class OperationTests(OperationTestBase): operation.database_backwards("test_alorwrtto", editor, new_state, project_state) self.assertColumnNotExists("test_alorwrtto_rider", "_order") + def test_alter_fk(self): + """ + Tests that creating and then altering an FK works correctly + and deals with the pending SQL (#23091) + """ + project_state = self.set_up_test_model("test_alfk") + # Test adding and then altering the FK in one go + create_operation = migrations.CreateModel( + name="Rider", + fields=[ + ("id", models.AutoField(primary_key=True)), + ("pony", models.ForeignKey(to="Pony")), + ], + ) + create_state = project_state.clone() + create_operation.state_forwards("test_alfk", create_state) + alter_operation = migrations.AlterField( + model_name='Rider', + name='pony', + field=models.ForeignKey(editable=False, to="Pony"), + ) + alter_state = create_state.clone() + alter_operation.state_forwards("test_alfk", alter_state) + with connection.schema_editor() as editor: + create_operation.database_forwards("test_alfk", editor, project_state, create_state) + alter_operation.database_forwards("test_alfk", editor, create_state, alter_state) + @unittest.skipIf(sqlparse is None and connection.features.requires_sqlparse_for_splitting, "Missing sqlparse") def test_run_sql(self): """ |
