Steve
Steve

Reputation: 1

Innodb foreign key constraints

I am trying to change the type in two tables of an innoDB. The problem is that the values are a key and a foreign key. When I try to make the change I get the following error

#1025 error on rename

Do I need to drop the foreign keys and then make the changes and then reapply the foreign key?

Upvotes: 0

Views: 210

Answers (2)

shane
shane

Reputation: 61

Since u can use the name to drop the foreign key first and the column then:

ALTER TABLE categories DROP FOREIGN KEY categories_ibfk_1;
ALTER TABLE categories DROP COLUMN assets_id;

To find out which table caused the error you can run

SHOW ENGINE INNODB STATUS\G 

and then look at the "LATEST FOREIGN KEY ERROR" section.

Upvotes: 1

racetrack
racetrack

Reputation: 3756

Yeah, you have to drop the foreign key. Try SHOW INNODB STATUS to see if there's a more elaborated explanation of what's going on.

Upvotes: 0

Related Questions