Kaydet (Commit) d4305a15 authored tarafından Andrew Godwin's avatar Andrew Godwin

[1.7.x] Fixed #22844: Duplicate SQL for SQLite FKs

üst 44a50603
...@@ -104,7 +104,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): ...@@ -104,7 +104,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
body['__module__'] = model.__module__ body['__module__'] = model.__module__
temp_model = type(model._meta.object_name, model.__bases__, body) temp_model = type(model._meta.object_name, model.__bases__, body)
# Create a new table with that format # Create a new table with that format. We remove things from the
# deferred SQL that match our table name, too
self.deferred_sql = [x for x in self.deferred_sql if model._meta.db_table not in x]
self.create_model(temp_model) self.create_model(temp_model)
# Copy data from the old table # Copy data from the old table
field_maps = list(mapping.items()) field_maps = list(mapping.items())
......
...@@ -156,6 +156,49 @@ class OperationTests(MigrationTestBase): ...@@ -156,6 +156,49 @@ class OperationTests(MigrationTestBase):
self.assertEqual(len(definition[2]), 0) self.assertEqual(len(definition[2]), 0)
self.assertEqual(definition[1][0], "Pony") self.assertEqual(definition[1][0], "Pony")
def test_create_model_with_unique_after(self):
"""
Tests the CreateModel operation directly followed by an
AlterUniqueTogether (bug #22844 - sqlite remake issues)
"""
operation1 = migrations.CreateModel(
"Pony",
[
("id", models.AutoField(primary_key=True)),
("pink", models.IntegerField(default=1)),
],
)
operation2 = migrations.CreateModel(
"Rider",
[
("id", models.AutoField(primary_key=True)),
("number", models.IntegerField(default=1)),
("pony", models.ForeignKey("test_crmoua.Pony")),
],
)
operation3 = migrations.AlterUniqueTogether(
"Rider",
[
("number", "pony"),
],
)
# Test the database alteration
project_state = ProjectState()
self.assertTableNotExists("test_crmoua_pony")
self.assertTableNotExists("test_crmoua_rider")
with connection.schema_editor() as editor:
new_state = project_state.clone()
operation1.state_forwards("test_crmoua", new_state)
operation1.database_forwards("test_crmoua", editor, project_state, new_state)
project_state, new_state = new_state, new_state.clone()
operation2.state_forwards("test_crmoua", new_state)
operation2.database_forwards("test_crmoua", editor, project_state, new_state)
project_state, new_state = new_state, new_state.clone()
operation3.state_forwards("test_crmoua", new_state)
operation3.database_forwards("test_crmoua", editor, project_state, new_state)
self.assertTableExists("test_crmoua_pony")
self.assertTableExists("test_crmoua_rider")
def test_create_model_m2m(self): def test_create_model_m2m(self):
""" """
Test the creation of a model with a ManyToMany field and the Test the creation of a model with a ManyToMany field and the
......
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