Magento 1.9 – Import Foreign Key Constraint Fails

databaseimportmagento-1.9

I am trying to import(with bigdump) my live database to an test database. While importing the tables to the test database im getting the following error.

MySQL: Cannot add or update a child row: a foreign key constraint fails (DB_Name.catalog_product_entity, CONSTRAINT FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID FOREIGN KEY (attribute_set_id) REFERENCES eav_attribute_set (attribute_set_id) ON )

I have set the SET Foreign_Key_Checks but it seems this isn't changing the error at all.

SET FOREIGN_KEY_CHECKS = 0;
//Code
SET FOREIGN_KEY_CHECKS = 1;

Do I need to change table names? What am I doing wrong?

Best Answer

I had the same problem. I ended importing my MySQL database dump using SSH.

This could be done like this:

  1. Upload the SQL file to the server.
  2. If the database does not exist please create one with an user. Note the username and password.
  3. Log into the server through SSH
  4. Navigate to the directory where your .sql file is.
  5. Type this this command: mysql -uUSERNAME -p DATABASE_NAME < data.sql

This works for me and it is also much faster.

Related Topic