mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #23091: CreateModel and AddField were clashing with deferred SQL
This commit is contained in:
parent
1b00738f73
commit
c06e124b5e
3 changed files with 72 additions and 1 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue