Removing foreign key tables on phpmyadmin? cannot refuse an index: foreign key constraint required

I tried to find a way to delete some foreign keys generated by mistake, but every time I DROP the table associated with a foreign key, it tries to erase it, it says: "Cannot delete index: restriction is necessary in a foreign key".

+6
source share
2 answers

On the Structure tab, click "see relational view" under the fields. Here you can delete foreign keys by selecting an empty value from the drop-down list.

+22
source

You need to remove the foreign key using the alter statement:

ALTER TABLE yourtable DROP CONSTRAINT yourforeignkeyname 

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

 SET FOREIGN_KEY_CHECKS=0; DROP TABLE yourtable; 

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

+5
source

Source: https://habr.com/ru/post/974695/


All Articles