How to Drop a Foreign Key in MySQL

To remove (drop) a foreign key constraint in MySQL use the following command:

ALTER TABLE `myTableName` DROP FOREIGN KEY `myForeignKeyName`;

If you do not know the name of the constraint, then use the command below:


It is possible that MySQL complains that the foreign key (index) is needed by some other constraint. This can be solved by first creating an index that is equal to to foreign key index. To know which fields to add to that index, use the SHOW CREATE TABLE command from above.

CREATE INDEX `myIndexName` ON `myTableName` (`myColumn1`, `myColumn2`) ;

Last modification:

This websites uses cookies and cookies of third parties for analytical purposes and advertisement. By using our website you agree to that. More information. You can change your choice any time.