mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #22844: Duplicate SQL for SQLite FKs
This commit is contained in:
parent
d17a4cb037
commit
c8c79367a2
@ -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):
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user