Are you trying to import a MySql dump file and getting the following error: “#1452 – Cannot add or update a child row: a foreign key constraint fails”? Its because of the foreign key validation checks.
You can run the following statement to get detailed error information:
SHOW ENGINE INNODB STATUS;
To import a Mysql dump file with foreign key constraints, open the MySql terminal and run the following statements:
mysql> SET foreign_key_checks = 0; mysql> SOURCE dump_file_name; mysql> SET foreign_key_checks = 1;
Alternatively, add
SET foreign_key_checks = 0;
at the beginning of the mysql dump file and
SET foreign_key_checks = 1;
at the end of the mysql dump file and then import the dump file to resolve the issue.
Leave a Comment