[Solved] MYSQL Error: Cannot delete or update a parent row: a foreign key constraint fails

1 problem
when deleting data or tables associated with foreign keys, MySQL reports an error:

Cannot delete or update a parent row: a foreign key constraint fails

2 solution

SET foreign_key_checks = 0; // First set the foreign key constraint check off

drop table mytable; // Delete the data, table or view

SET foreign_key_checks = 1; // Turn on foreign key constraint checking to maintain the structural integrity of the table
First turn off foreign key constraints, perform the delete operation, and then turn on foreign key constraints

Similar Posts: