mohlal asked this 3 years ago

Drop table Mysql bypass foreign key constraint

How to get around foreign key constraint check while dropping tables?

mysql> drop table users;

ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

mysql> drop table questions;

ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails


Best Answer by dig_abacus
3 likes

You can temporarily disable foreign key checks

mysql> SET FOREIGN_KEY_CHECKS=0;

mysql> DROP TABLE USERS;

After dropping table you can enable the checks again. It is not wise to disble the checks permanently.

mysql> SET FOREIGN_KEY_CHECKS=1;