Resolve foreign key Can not delete or update a parent row: a foreign key constraint fails the mysql error

1 issue

Delete the foreign key data or time table, mysql error appears:

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


2 Solutions

    SET foreign_key_checks = 0; // to set off the foreign key constraint checking
     
    drop table mytable; // delete the data, table or view
     
    SET foreign_key_checks = 1; // Open a foreign key constraint checking, in order to maintain the structural integrity of the table

Turn off foreign key constraints, perform the removal, and then turn the foreign key constraint

Guess you like

Origin blog.csdn.net/tjls2008/article/details/90777960