Question

I get the following error while trying to reindex my magento database..

Product Flat Data index process unknown error: exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint >violation: 1452 Cannot add or update a child row: a foreign key constraint fails >(d014505f., CONSTRAINT >FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID FOREIGN KEY (entity_id) >REFERENCES catalog_product_entity (`e)' in >/www/htdocs/w00f5624/lib/Zend/Db/Statement/Pdo.php:228

How do i fix this??

Was it helpful?

Solution

as stated correctly by Sander, deleted products still present in the product flat table cause this error. Anyway, truncating the whole table will not be necessary. You can find these products by this SQL-query:

SELECT pf1.entity_id
FROM catalog_product_flat_1 pf1
LEFT JOIN catalog_product_entity p ON pf1.entity_id = p.entity_id
WHERE ISNULL( p.entity_id ) 

You will then have to delete these items, which can be done using this SQL-query:

DELETE pf1.*
FROM catalog_product_flat_1 pf1
LEFT JOIN catalog_product_entity p ON pf1.entity_id = p.entity_id
WHERE ISNULL( p.entity_id ) 

Taken from here (German): http://www.avs-webentwicklung.de/nc/blog/artikel/magento-fehler-beim-index-aufbau-sofortmassnahmen.html

Ask me if u need more advise.

OTHER TIPS

i've had this issue before. I solved it by truncating the product_flat_data tables and afterwards reindexing. It's caused by non existing products still present in the table.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top