[Django] #26781: Bug with migrate appears if you try to change the db_table value

10 views
Skip to first unread message

Django

unread,
Jun 20, 2016, 7:39:31 AM6/20/16
to django-...@googlegroups.com
#26781: Bug with migrate appears if you try to change the db_table value
----------------------------+---------------------
Reporter: laozzzi | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords: migrate
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------
Problem appears after renaming db_table, if you try to rename, for example
"Article" to "article" or "Blog" to "blog" or to "bLoG", etc.

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"

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26781>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 20, 2016, 7:40:43 AM6/20/16
to django-...@googlegroups.com
#26781: Bug with migrate appears if you try to change the db_table value
----------------------------+--------------------------------------

Reporter: laozzzi | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by laozzzi):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> Problem appears after renaming db_table, if you try to rename, for
> example "Article" to "article" or "Blog" to "blog" or to "bLoG", etc.
>
> 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"
>
> 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.

New description:

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"

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:1>

Django

unread,
Jun 20, 2016, 7:43:10 AM6/20/16
to django-...@googlegroups.com
#26781: Bug with migrate appears if you try to change the db_table value
----------------------------+--------------------------------------

Reporter: laozzzi | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by laozzzi:

Old description:

> 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"
>
> 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.

New description:

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:2>

Django

unread,
Jun 20, 2016, 7:47:24 AM6/20/16
to django-...@googlegroups.com
#26781: Bug with migrate appears if you try to change the db_table value
----------------------------+--------------------------------------
Reporter: laozzzi | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: duplicate

Keywords: migrate | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => duplicate


Comment:

Looks like a duplicate of #23577

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:3>

Django

unread,
Jun 20, 2016, 7:59:48 AM6/20/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
----------------------------+------------------------------------

Reporter: laozzzi | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: migrate | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

The database is SQLite.

Django

unread,
Jun 20, 2016, 10:36:39 AM6/20/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
----------------------------+------------------------------------
Reporter: laozzzi | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+------------------------------------
Changes (by charettes):

* version: 1.9 => master


Comment:

The underlying issue here is that SQLite always deal with identifiers in a
case-insensitive way, even if quoted.

e.g.

{{{#!sql
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

{{{#!sql
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()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:4>

Django

unread,
Jun 20, 2016, 10:38:56 AM6/20/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
--------------------------------+------------------------------------

Reporter: laozzzi | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migrate sqlite | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by charettes):

* keywords: migrate => migrate sqlite


--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:5>

Django

unread,
Jun 20, 2016, 4:04:07 PM6/20/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
--------------------------------+------------------------------------
Reporter: laozzzi | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migrate sqlite | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by shaib):

* cc: shaib (added)


Comment:

Plenty of case issues in the Oracle backend as well; perhaps we should do
something more general. See for example #20226, #20487

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:6>

Django

unread,
Jun 20, 2016, 11:34:07 PM6/20/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
--------------------------------+-------------------------------------
Reporter: laozzzi | Owner: charettes
Type: Bug | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migrate sqlite | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------+-------------------------------------
Changes (by charettes):

* status: new => assigned
* owner: nobody => charettes


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:7>

Django

unread,
Jun 21, 2016, 12:06:48 AM6/21/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
-------------------------------------+-------------------------------------

Reporter: laozzzi | Owner: charettes
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migrate sqlite case | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* keywords: migrate sqlite => migrate sqlite case
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6814 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:8>

Django

unread,
Jun 21, 2016, 11:34:25 AM6/21/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
-------------------------------------+-------------------------------------
Reporter: laozzzi | Owner: charettes
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: migrate sqlite case | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:9>

Django

unread,
Jun 21, 2016, 4:37:40 PM6/21/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
-------------------------------------+-------------------------------------
Reporter: laozzzi | Owner: charettes
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: migrate sqlite case | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette <charette.s@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917" c2e62fd]:
{{{
#!CommitTicketReference repository=""
revision="c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917"
Fixed #26781 -- Made table name case change a noop on SQLite.

SQLite disgresses from the SQL standard by ignoring case of quoted
identifiers.

Thanks to laozzzi for the report and Tim for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:10>

Django

unread,
Jun 21, 2016, 4:38:31 PM6/21/16
to django-...@googlegroups.com
#26781: SQLite crashes when changing the case of db_table
-------------------------------------+-------------------------------------
Reporter: laozzzi | Owner: charettes
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed
Keywords: migrate sqlite case | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette <charette.s@…>):

In [changeset:"23ac35af19face4ad0b466f5aaffafd5db98db0e" 23ac35a]:
{{{
#!CommitTicketReference repository=""
revision="23ac35af19face4ad0b466f5aaffafd5db98db0e"
[1.10.x] Fixed #26781 -- Made table name case change a noop on SQLite.

SQLite disgresses from the SQL standard by ignoring case of quoted
identifiers.

Thanks to laozzzi for the report and Tim for the review.

Backport of c2e62fd1aed093c4d9ff84e3d86e6a85c8aa1917 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26781#comment:11>

Reply all
Reply to author
Forward
0 new messages