Database Import Constraint Fail – Magento 1.9 Solution

databasemagento-1.9MySQL

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!

Best Answer

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

Related Topic