3

I've got a working Magento website hosted on a development server but I've decided to take a local copy to make it easier to work on.

I've downloaded the source files and imported the database. All looks to be working perfectly, I can see all of my products and I can't see any problems - but during this import, I noticed this error:

My.Name@NETWORK c:\xampp\htdocs\website
# mysql -u root database < database.sql
ERROR 1452 (23000) at line 415010: Cannot add or update a child row: a foreign key constraint fails (`database`.`#sql-be4_32`, CONSTRAINT `FK_CATALOG_EAV_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE )

Will this error have stopped certain data from being imported. Everything at the moment looks fine and ideally I would like to continue and ignore the error - but I don't want it to bite me in days/weeks to come!

2

You are trying to add a record into catalog_eav_attribute, but you do not have a corresponding record in eav_attribute that matches on attribute_id

If you are also inserting bulk data into eav_attribute, I would recommend doing that first, and then the data would be in the table before the foreign key on catalog_eav_attribute needed to reference it.

This article discusses how you can use:

SET FOREIGN_KEY_CHECKS = 0; --Do your update here SET FOREIGN_KEY_CHECKS = 1;

If you cannot change the order that you are inserting data. You just have to make sure your data follows the Foreign Keys once everything has been inserted into the database, before you can re-enable the FOREIGN_KEY_CHECKS

Source: https://stackoverflow.com/a/8306636

2
  • So I should edit my .sql file, adding SET FOREIGN_KEY_CHECKS = 0; at the start and SET FOREIGN_KEY_CHECKS = 1; at the end - then reupload my file? Nov 6 '15 at 12:12
  • 2
    Yea, just be aware the reason the reason for the foreign key check, is data integrity so some data may be missing and/or duplicated. More details: w3schools.com/sql/sql_foreignkey.asp
    – B00MER
    Nov 6 '15 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.