MySQL 1452 foreign key constraint error - import Magento

I am trying to import a sql magento dump along with some product data, and I get this foreign key constraint error:

`ERROR 1452 (23000) at line 231680: Cannot add or update a child row: a foreign key constraint fails: `magento`.`#sql-b33_27`, CONSTRAINT `FK_CATALOG_COMPARE_ITEM_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE CASCADE ON )` 

This is the sql code causing the error:

 -- -- Constraints for table `catalog_eav_attribute` -- ALTER TABLE `catalog_eav_attribute` ADD CONSTRAINT `FK_CATALOG_EAV_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE; 

I am not very comfortable with sql queries. Can someone please explain to me what this request is doing and tell me how to solve it? Thanks.

+7
source share
2 answers

You are trying to add an entry to catalog_eav_attribute , but you do not have a corresponding entry in eav_attribute that matches attribute_id

If you also insert massive data into eav_attribute , I would recommend doing it first, and then the data will be in the table before the foreign key to catalog_eav_attribute should 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 insertion order of the data. You just need to make sure your data follows foreign keys as soon as everything has been inserted into the database before you can enable FOREIGN_KEY_CHECKS again

+16
source

I used the database recovery tool, after which I did it in SQL:

TABLE DROP catalog_product_flat_1 , catalog_product_flat_2 , catalog_product_flat_3 ;

Now the index is built successfully.

0
source

All Articles