Fixed #22168 -- Fixed migrations failing on sqlite when column names are SQL keywords
Thanks to trac user fallen_flint for the report and initial patch.
This commit is contained in:
parent
a19f0d0c1e
commit
c679cb7f60
|
@ -83,8 +83,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||||
field_maps = list(mapping.items())
|
field_maps = list(mapping.items())
|
||||||
self.execute("INSERT INTO %s (%s) SELECT %s FROM %s" % (
|
self.execute("INSERT INTO %s (%s) SELECT %s FROM %s" % (
|
||||||
self.quote_name(temp_model._meta.db_table),
|
self.quote_name(temp_model._meta.db_table),
|
||||||
', '.join(x for x, y in field_maps),
|
', '.join(self.quote_name(x) for x, y in field_maps),
|
||||||
', '.join(y for x, y in field_maps),
|
', '.join(self.quote_name(y) for x, y in field_maps),
|
||||||
self.quote_name(model._meta.db_table),
|
self.quote_name(model._meta.db_table),
|
||||||
))
|
))
|
||||||
# Delete the old table
|
# Delete the old table
|
||||||
|
|
|
@ -195,6 +195,23 @@ class OperationTests(MigrationTestBase):
|
||||||
operation.database_backwards("test_adfl", editor, new_state, project_state)
|
operation.database_backwards("test_adfl", editor, new_state, project_state)
|
||||||
self.assertColumnNotExists("test_adfl_pony", "height")
|
self.assertColumnNotExists("test_adfl_pony", "height")
|
||||||
|
|
||||||
|
def test_column_name_quoting(self):
|
||||||
|
"""
|
||||||
|
Column names that are SQL keywords shouldn't cause problems when used
|
||||||
|
in migrations (#22168).
|
||||||
|
"""
|
||||||
|
project_state = self.set_up_test_model("test_regr22168")
|
||||||
|
operation = migrations.AddField(
|
||||||
|
"Pony",
|
||||||
|
"order",
|
||||||
|
models.IntegerField(default=0),
|
||||||
|
)
|
||||||
|
new_state = project_state.clone()
|
||||||
|
operation.state_forwards("test_regr22168", new_state)
|
||||||
|
with connection.schema_editor() as editor:
|
||||||
|
operation.database_forwards("test_regr22168", editor, project_state, new_state)
|
||||||
|
self.assertColumnExists("test_regr22168_pony", "order")
|
||||||
|
|
||||||
def test_add_field_preserve_default(self):
|
def test_add_field_preserve_default(self):
|
||||||
"""
|
"""
|
||||||
Tests the AddField operation's state alteration
|
Tests the AddField operation's state alteration
|
||||||
|
|
Loading…
Reference in New Issue