Renaming foreign-key columns in MySQL
AFAIK, dropping the constraint, then rename, then add the constraint back is the only way. Backup first!
AFAIK, dropping the constraint, then rename, then add the constraint back is the only way. Backup first!
There is probably another table with a foreign key referencing the primary key you are trying to change. To find out which table caused the error you can run SHOW ENGINE INNODB STATUS and then look at the LATEST FOREIGN KEY ERROR section.
You usually get this error if your tables use the InnoDB engine. In that case you would have to drop the foreign key, and then do the alter table and drop the column. But the tricky part is that you can’t drop the foreign key using the column name, but instead you would have to … Read more
As explained here, seems the foreign key constraint has to be dropped by constraint name and not the index name. The syntax is: ALTER TABLE footable DROP FOREIGN KEY fooconstraint;
Lone Ranger is very close… in fact, you also need to specify the datatype of the renamed column. For example: ALTER TABLE `xyz` CHANGE `manufacurerid` `manufacturerid` INT; Remember : Replace INT with whatever your column data type is (REQUIRED) Tilde/ Backtick (`) is optional