Magento 1.7 cannot reindex product flat data

David Vendryes picture David Vendryes · Mar 22, 2013 · Viewed 11.6k times · Source

Magento 1.7 cannot reindex product flat data... I get the following error when trying to reindex my 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`.<result 2 when explaining filename '#sql-1f6c_39a11d'>, 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

Stack trace:#0 /www/htdocs/w00f5624/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement-    >execute(Array)
#1 /www/htdocs/w00f5624/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /www/htdocs/w00f5624/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /www/htdocs/w00f5624/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /www/htdocs/w00f5624/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('ALTER TABLE `ca...', Array)
#5 /www/htdocs/w00f5624/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLE `ca...', Array)
#6 /www/htdocs/w00f5624/lib/Varien/Db/Adapter/Pdo/Mysql.php(340): Varien_Db_Adapter_Pdo_Mysql->query('ALTER TABLE `ca...')
#7 /www/htdocs/w00f5624/lib/Varien/Db/Adapter/Pdo/Mysql.php(2569): Varien_Db_Adapter_Pdo_Mysql->raw_query('ALTER TABLE `ca...')
#8 /www/htdocs/w00f5624/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(816): Varien_Db_Adapter_Pdo_Mysql->addForeignKey('FK_CAT_PRD_FLAT...', 'catalog_product...', 'entity_id', 'catalog_product...', 'entity_id', 'CASCADE', 'CASCADE')
#9 /www/htdocs/w00f5624/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1390): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(1)
#10 /www/htdocs/w00f5624/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#11 /www/htdocs/w00f5624/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#12 /www/htdocs/w00f5624/app/code/core/Mage/Index/Model/Process.php(209): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#13 /www/htdocs/w00f5624/app/code/core/Mage/Index/Model/Process.php(255): Mage_Index_Model_Process->reindexAll()
#14 /www/htdocs/w00f5624/shell/indexer.php(158): Mage_Index_Model_Process->reindexEverything()
#15 /www/htdocs/w00f5624/shell/indexer.php(198): Mage_Shell_Compiler->run()
#16 {main}

Answer

Mohammad Alsallal picture Mohammad Alsallal · Mar 23, 2013

It seems Magento did not clean the table when you have deleted some informations; so you need to clean it manually, using this SQL query:

TRUNCATE TABLE ´catalog_product_flat_1´;

Then, run reindex process.

It's okay to empty that table; since Magento uses EAV tables to rebiuld (reindex) it again.