Cannot Drop Column : Needed In A Foreign Key Constraint


Answer :

Having a look at MySql docs I've found a warning about foreign_key_keys:

Warning
With foreign_key_checks=0, dropping an index required by a foreign key constraint places the table in an inconsistent state and causes the foreign key check that occurs at table load to fail. To avoid this problem, remove the foreign key constraint before dropping the index (Bug #70260).

IMHO you should drop FOREIGN KEY before DROP the COLUMN.

ALTER TABLE `user` DROP FOREIGN KEY `FK_G38T6P7EKUXYWH1`; ALTER TABLE `user` DROP COLUMN `region_id`; 

I've set up a rextester example, check it here.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?