[MDEV-23950] Renaming a column that is used as a foreign key throws an error Created: 2020-10-13 Updated: 2020-10-13 Resolved: 2020-10-13 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | N/A |
| Affects Version/s: | 10.5.4, 10.5.5, 10.5.6 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Minor |
| Reporter: | Alexander Karlstad | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 2 |
| Labels: | None | ||
| Environment: |
Docker, mariadb/latest |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
Renaming a column (usually the primary key) that is used as a foreign key in another table with ALTER TABLE syntax (not the new RENAME COLUMN syntax from 10.5.2) causes a Cannot drop index 'PRIMARY': needed in a foreign key constraint error. For example, say you have these two tables:
And you add a foreign key constraint:
And then try to rename test.testId to test.id with this syntax:
You will get the error mentioned. Turning off foreign key checks before and after this alter statement will make it work though, and from what I can tell the references in information_schema.KEY_COLUMN_USAGE is correctly updated, but it does not feel right. Also, if using the more recent RENAME COLUMN syntax, the change goes through without any errors. The problem is that this syntax is fairly new and likely not implemented in a lot of libraries yet, like doctrine/dbal for instance. |
| Comments |
| Comment by Alice Sherepa [ 2020-10-13 ] | ||||||||
|
it looks like the same problem as | ||||||||
| Comment by Alexander Karlstad [ 2020-10-13 ] | ||||||||
I agree, it does seem like the same problem. My output:
| ||||||||
| Comment by Alexander Karlstad [ 2020-10-13 ] | ||||||||
|
I have attached the output of
in its entirety to this issue now by the way. | ||||||||
| Comment by Alice Sherepa [ 2020-10-13 ] | ||||||||
|
Thanks! Let's track further progress in |