简体   繁体   中英

Deleting foreign key tables on phpmyadmin? cannot drop index: needed in foreign key constraint

I've been trying to find a way to delete some foreign keys generated by mistake, but each time I DROP the table associated with the foreign key to try and erase it, it says "cannot drop index: needed in foreign key constraint".

In "Structure" tab, click on "see relational view" below the fields. Here you can remove the foreign keys by selecting an empty value in the dropdown.

You have to delete the foreign key with an alter statement:

ALTER TABLE yourtable DROP CONSTRAINT yourforeignkeyname

You might be able to force drop it as well (works in the MySQL console but might not work in phpmyadmin as I'm not sure how sessions are handled)

SET FOREIGN_KEY_CHECKS=0; DROP TABLE yourtable;

Note: this is very dangerous and not recommended if you're seriously using foreign keys.

The best way to drop a table with relation in phpmyadmin, click on "SQL" tab, uncheck Enable foreign key checks and run: DROP TABLE yourtablename .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM