[Django] #24995: MySQL error in migrations

19 views
Skip to first unread message

Django

unread,
Jun 17, 2015, 11:43:31 AM6/17/15
to django-...@googlegroups.com
#24995: MySQL error in migrations
-------------------------------+--------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords: rename mysql error
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------
In a migration where a primary-key field is renamed, a mysql error occurs,
because mysql needs foreign keys to be disabled/dropped for that
operation.

See here for an example of the error you would get:
http://stackoverflow.com/questions/4080611/1025-error-on-rename-of-
database-sql-2e0f-1254ba7-to-database-table


I have a patch which fixes the issue:
https://github.com/EikeDehling/django/commit/dbe0c4692fe1a7d73e4de345a171b8cbb35651b2

Please let me know what i can do to get this merged/fixed in django.

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

Django

unread,
Jun 17, 2015, 11:48:44 AM6/17/15
to django-...@googlegroups.com
#24995: MySQL error when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 1
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

A regression test in `tests/schema` is also needed.

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

Django

unread,
Jun 18, 2015, 5:25:13 AM6/18/15
to django-...@googlegroups.com
#24995: MySQL error when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by EikeDehling):

Commit with test here:
https://github.com/EikeDehling/django/commit/72aa1b92551137da69104ab917079ea7e3ac8854

This would only fail on mysql though, which the test-framework does not
use i think?

So the test also passes without my patch.

Suggestions?

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

Django

unread,
Jun 18, 2015, 7:38:51 AM6/18/15
to django-...@googlegroups.com
#24995: MySQL error when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by timgraham):

You need to [https://docs.djangoproject.com/en/dev/internals/contributing
/writing-code/unit-tests/#using-another-settings-module create another
settings file] in order to run the tests with a different database. Please
send a pull request with the fix and test.

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

Django

unread,
Jun 18, 2015, 10:30:50 AM6/18/15
to django-...@googlegroups.com
#24995: MySQL error when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by EikeDehling):

Thanks, testing with settings for mysql indeed shows the issue

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

Django

unread,
Jun 18, 2015, 10:32:18 AM6/18/15
to django-...@googlegroups.com
#24995: MySQL error when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+------------------------------------

Comment (by EikeDehling):

https://github.com/django/django/pull/4881

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

Django

unread,
Jun 29, 2015, 5:31:24 PM6/29/15
to django-...@googlegroups.com
#24995: MySQL error when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1
* needs_tests: 1 => 0


Comment:

The current test on the pull request doesn't appear to be a regression
test as it passes even with the fix reverted.

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

Django

unread,
Mar 30, 2016, 9:22:56 AM3/30/16
to django-...@googlegroups.com
#24995: MySQL 5.5.x errno: 150 when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

Comment (by timgraham):

As noted in ticket:26384#comment:16:

Prior to MySQL 5.6.6, adding and dropping a foreign key in the same ALTER
TABLE statement may be problematic in some cases and is therefore
unsupported. Separate statements should be used for each operation. As of
MySQL 5.6.6, adding and dropping a foreign key in the same ALTER TABLE
statement is supported for ALTER TABLE ... ALGORITHM=INPLACE but remains
unsupported for ALTER TABLE ... ALGORITHM=COPY.

So the reason I didn't find the proposed test to be a regression test is
because I'm using a newer version of MySQL. The test added in #26384 is
similar to the one proposed in the pull request and has revealed the
issue. Unfortunately both the test added in the other ticket and the test
proposed in the pull request for this ticket are still failing on MySQL
5.5.x, even with the proposed fix (`OperationalError: (1025, "Error on
rename of './test_django/#sql-58c_2b9' to './test_django/schema_author'
(errno: 150)")`).

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

Django

unread,
Mar 31, 2016, 12:01:07 PM3/31/16
to django-...@googlegroups.com
#24995: MySQL 5.5.x errno: 150 when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"f3595b25496691966d4ff858a3b395735ad85a6e" f3595b2]:
{{{
#!CommitTicketReference repository=""
revision="f3595b25496691966d4ff858a3b395735ad85a6e"
Refs #26384, #24995 -- Skipped a schema test on older MySQL versions.
}}}

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

Django

unread,
Mar 31, 2016, 12:17:06 PM3/31/16
to django-...@googlegroups.com
#24995: MySQL 5.5.x errno: 150 when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"a0e3cbaa2bcbab682dfc3fb2998c3b43b21a3741" a0e3cbaa]:
{{{
#!CommitTicketReference repository=""
revision="a0e3cbaa2bcbab682dfc3fb2998c3b43b21a3741"
[1.9.x] Refs #26384, #24995 -- Skipped a schema test on older MySQL
versions.

Backport of f3595b25496691966d4ff858a3b395735ad85a6e from master
}}}

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

Django

unread,
Apr 2, 2016, 8:17:44 AM4/2/16
to django-...@googlegroups.com
#24995: MySQL 5.5.x errno: 150 when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"d81d02d449edd046a94de5f171f4ae87fa331c7d" d81d02d]:
{{{
#!CommitTicketReference repository=""
revision="d81d02d449edd046a94de5f171f4ae87fa331c7d"
Refs #26384, #24995 -- Avoided a module-level MySQL query in the schema
tests.
}}}

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

Django

unread,
Apr 2, 2016, 8:18:20 AM4/2/16
to django-...@googlegroups.com
#24995: MySQL 5.5.x errno: 150 when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Normal | Resolution:
Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"5c1944f9184649a05b3c18b17636bf61c8613f9c" 5c1944f9]:
{{{
#!CommitTicketReference repository=""
revision="5c1944f9184649a05b3c18b17636bf61c8613f9c"
[1.9.x] Refs #26384, #24995 -- Avoided a module-level MySQL query in the
schema tests.

Backport of d81d02d449edd046a94de5f171f4ae87fa331c7d from master
}}}

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

Django

unread,
Sep 4, 2017, 3:41:19 PM9/4/17
to django-...@googlegroups.com
#24995: MySQL 5.5.x errno: 150 when renaming a primary key
------------------------------------+------------------------------------
Reporter: EikeDehling | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: wontfix

Keywords: rename mysql error | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

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


Comment:

It looks like a patch isn't forthcoming and master will drop support for
MySQL 5.5 following Django 2.0 alpha (#28552), so I think we can close
this.

--
Ticket URL: <https://code.djangoproject.com/ticket/24995#comment:12>

Reply all
Reply to author
Forward
0 new messages