#26781 closed Bug (fixed)
SQLite crashes when changing the case of db_table
Reported by: | lao zzzi | Owned by: | Simon Charette |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | migrate sqlite case |
Cc: | Shai Berger | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Problem appears after renaming db_table, if you try to rename, for example "Article" to "article" or "Blog" to "blog" or to "bLoG", etc. and migrate this changes to database
Example:
Step 1. Create model:
class Article (models.Model): class Meta(): db_table="Article" title = models.CharField(max_length=200) body = models.TextField() date_cr = models.DateTimeField()
Step 2. make migrations & migrate
Step 3. change the value of db_table from "Article" to "article"
class Article (models.Model): class Meta(): db_table="article" title = models.CharField(max_length=200) body = models.TextField() date_cr = models.DateTimeField()
Step 4. make migrations
Step 5. migrate -- here you'll see errors
.....
django.db.utils.OperationalError: there is already another table or index with this name: article
This error appears any time later, if you try to do something with model and use migrate. Even if you delete the Article model and start "make migrations & migrate" you'll see such error.
Change History (11)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
Description: | modified (diff) |
---|
comment:3 by , 9 years ago
Summary: | Bug with migrate appears if you try to change the db_table value → SQLite crashes when changing the case of db_table |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 9 years ago
Version: | 1.9 → master |
---|
The underlying issue here is that SQLite always deal with identifiers in a case-insensitive way, even if quoted.
e.g.
CREATE TABLE Foo ( id integer primary key); CREATE TABLE foo ( id integer primary key);
Will crash on all SQL compliant backends as the Foo
will be lowercased to foo
since it's not quoted.
However the following will only crash on SQLite
CREATE TABLE "Foo" ( id integer primary key); CREATE TABLE "foo" ( id integer primary key);
I guess we should add a feature flag for this and make alter_db_table a noop if ignores_quoted_identifier_case and old_table_name.lower() == new_table_name.lower()
.
comment:5 by , 9 years ago
Keywords: | sqlite added |
---|
comment:6 by , 9 years ago
Cc: | added |
---|
comment:7 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
While there's clearly multiple issues in the Oracle backend it behaves correctly in regard to identifier quoting.
The root of all its problems is the fact identifiers are both uppercased and quoted making it impossible to reference non upper cased identifiers.
In the case of SQLite it digresses from SQL92 by treating delimited identifier in a case-insensitive way. This is not an issue with column name alteration as the table is rebuilt anyway.
comment:9 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
The database is SQLite.