Articles in this section

Unable to import a database dump: Cannot add or update a child row: a foreign key constraint fails

Plesk for Windows Plesk for Linux kb: technical ABT: Group B

Applicable to:

  • Plesk for Linux
  • Plesk for Windows

Symptoms

When importing a database dump at Domains > example.com > Databases > Import Dump, the operation fails with one of the following error messages in Plesk:

PLESK_ERROR: Unable to import the example_com dump:
ERROR 1452 (23000) at line 4907226: Cannot add or update a child row: a foreign key constraint fails 

PLESK_ERROR: Unable to import the example_com dump:
ERROR 1215 (HY000) at line 15: Cannot add foreign key constraint

PLESK_ERROR: Unable to import the example_com dump:
ERROR 1215 (HY000) at line 15: Cannot delete or update a parent row: a foreign key constraint fails

Cause

Incorrect database design.

Resolution

Apply one of the following solutions.

Disabling foreign key check in the database dump file (any MySQL version)

 

  1. Open a database dump in a text editor.
  2. Add the line below at the beginning of the file:

    CONFIG_TEXT: SET FOREIGN_KEY_CHECKS=0;

  3. Go back to Plesk and restore this dump at Domains > example.com > Databases > Import Dump.
Disabling foreign key check in MySQL (MySQL versions 5.5 and greater)

 

  1. Connect to your Plesk server via SSH.
  2. Start MySQL:

    # plesk db

  3. Temporary disable foreign key checks in MySQL with the command:

    MYSQL_LIN: mysql> SET GLOBAL FOREIGN_KEY_CHECKS=0;

  4. Go back to Plesk and restore the database dump at Domains > example.com > Databases > Import Dump.
  5. Enable foreign key checks in MySQL back:

    MYSQL_LIN: mysql> SET GLOBAL FOREIGN_KEY_CHECKS=1;

  6. Exit MySQL:

    MYSQL_LIN: mysql> exit

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.