how to modify the foreign key column name and how to drop foreign key in Mysql when we drop than Error 150 comes and when modify or rename than error 152 comes
Asked
Active
Viewed 1,428 times
0
-
Possible duplicate of [Renaming foreign-key columns in MySQL](http://stackoverflow.com/questions/2014498/renaming-foreign-key-columns-in-mysql) – Amit Dec 16 '16 at 06:01
1 Answers
0
while trying to drop a foreign key, use the constraint name rather than the column name of the foreign key
ALTER TABLE `table_name` DROP FOREIGN KEY `id_name_fk`
and
ALTER TABLE `thetable`
DROP KEY `oldkey`,
ADD KEY `newkey` (`tablefield`);
or
ALTER TABLE table_name
DROP FOREIGN KEY 'table_name_consraint',
ADD CONSTRAINT `fk_table_name_consraint` FOREIGN KEY (`column`) REFERENCES `table_name` (`column`);

Chanukya
- 5,833
- 1
- 22
- 36