Opened 11 years ago
Closed 11 years ago
#22168 closed Bug (fixed)
Sqlite3 backend fails during _remake_table with column named "order"
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
It seems that column names should be quoted, cause if I try migrate my app, migration fails on following sql request:
INSERT INTO "services_group__new" (description, order, id, slug, title) SELECT description, order, id, slug, title FROM "services_group"
If I try it in db shell, it fails too, as expected.
Message is "Error: near "order": syntax error"
Adding quotes around column names in django.db.backends.sqlite3.schema.DatabaseSchemaEditor._remake_table fixes the problem for me:
-
django/db/backends/sqlite3/schema.py
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index 279ac4b..e8fc263 100644
a b class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): 83 83 field_maps = list(mapping.items()) 84 84 self.execute("INSERT INTO %s (%s) SELECT %s FROM %s" % ( 85 85 self.quote_name(temp_model._meta.db_table), 86 ', '.join( xfor x, y in field_maps),87 ', '.join( yfor x, y in field_maps),86 ', '.join(self.quote_name(x) for x, y in field_maps), 87 ', '.join(self.quote_name(y) for x, y in field_maps), 88 88 self.quote_name(model._meta.db_table), 89 89 )) 90 90 # Delete the old table
Change History (6)
comment:1 by , 11 years ago
Type: | Uncategorized → Bug |
---|
comment:2 by , 11 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 11 years ago
Component: | Database layer (models, ORM) → Migrations |
---|
comment:4 by , 11 years ago
Needs tests: | unset |
---|
Tentative pull request (with tests) here: https://github.com/django/django/pull/2378
Reviews welcome.
comment:5 by , 11 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hi,
I can reproduce the issue by doing the following:
1) Create a model with a field called
order
.2) Run
makemigrations
. This creates a first migration file.3) Add another field to the model created in 1)
4) Run
makemigrations
again. This creates a second migration file.5) Attempt to run
migrate
. This fails with the reported error.Your proposed fix looks sensible and it works for the reported issue but a full patch should have some tests too.
Thanks.