Opened 9 years ago

Closed 7 years ago

#24995 closed Bug (wontfix)

MySQL 5.5.x errno: 150 when renaming a primary key

Reported by: EikeDehling Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords: rename mysql error
Cc: eike@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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.

Change History (12)

comment:1 by Tim Graham, 9 years ago

Needs tests: set
Summary: MySQL error in migrationsMySQL error when renaming a primary key
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

A regression test in tests/schema is also needed.

comment:2 by EikeDehling, 9 years ago

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?

comment:3 by Tim Graham, 9 years ago

You need to create another settings file in order to run the tests with a different database. Please send a pull request with the fix and test.

comment:4 by EikeDehling, 9 years ago

Thanks, testing with settings for mysql indeed shows the issue

comment:6 by Tim Graham, 9 years ago

Needs tests: unset
Patch needs improvement: set

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

comment:7 by Tim Graham, 9 years ago

Summary: MySQL error when renaming a primary keyMySQL 5.5.x errno: 150 when renaming a primary key

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

comment:8 by Tim Graham <timograham@…>, 9 years ago

In f3595b2:

Refs #26384, #24995 -- Skipped a schema test on older MySQL versions.

comment:9 by Tim Graham <timograham@…>, 9 years ago

In a0e3cbaa:

[1.9.x] Refs #26384, #24995 -- Skipped a schema test on older MySQL versions.

Backport of f3595b25496691966d4ff858a3b395735ad85a6e from master

comment:10 by Tim Graham <timograham@…>, 9 years ago

In d81d02d:

Refs #26384, #24995 -- Avoided a module-level MySQL query in the schema tests.

comment:11 by Tim Graham <timograham@…>, 9 years ago

In 5c1944f9:

[1.9.x] Refs #26384, #24995 -- Avoided a module-level MySQL query in the schema tests.

Backport of d81d02d449edd046a94de5f171f4ae87fa331c7d from master

comment:12 by Tim Graham, 7 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top