[ MySQL drop field; foreign key errorno 150 ]
Problems with MySQL using InnoDB and dropping an unused, foreign key. The foreign key references another table's id. However, I don't need this field.
I've tried removing the fk index, which doesn't work - says it's needed in a foreign key contraint. And removing the field, which gives me an error:
1025 - Error on rename of './axis/#sql-ad8_1531' to './axis/Schedule' (errno: 150)
The table is currently empty. There are no tables referencing this field. Any ideas on how to get rid of this? Other than creating a new table?
If I'm reading the below error correctly, I can't drop the column since the fk index is declared. And I can't drop the index, because the column exists. Chicken & Egg??
LATEST FOREIGN KEY ERROR
111004 17:05:40 Error in foreign key constraint of table axis/Schedule:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
CONSTRAINT "fk_Schedule_Grp" FOREIGN KEY ("idGrp") REFERENCES "Grp" ("idGrp") ON DELETE NO ACTION ON UPDATE NO ACTION
InnoDB: Renaming table axis
. to axis
.Schedule
failed!
Answer 1
You need to use
ALTER TABLE table_name DROP FOREIGN KEY constraint_name
Here constraint_name
is the name of the constraint rather than the index. If you do not know what this is, you can find out by issuing a SHOW CREATE TABLE
. It is the identifier that appears after the word CONSTRAINT
.
Edit: From your addition to the question, it looks like you need to issue
ALTER TABLE table_name DROP FOREIGN KEY fk_Schedule_Grp