Opened 10 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 , 10 years ago
Needs tests: | set |
---|---|
Summary: | MySQL error in migrations → MySQL error when renaming a primary key |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 10 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 , 10 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:6 by , 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 , 9 years ago
Summary: | MySQL error when renaming a primary key → MySQL 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:12 by , 7 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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.
A regression test in
tests/schema
is also needed.