A client mentioned that he kept having to reindex the Product Flat Data but the notification in the admin section never went away. While trying to reindex from command line I was greeted with the following error:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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 (`koopjedeal`.`#sql-1606_faff0b`, CONSTRAINT `FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UP)’ in /var/www/koopjedeal/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /var/www/koopjedeal/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /var/www/koopjedeal/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /var/www/koopjedeal/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /var/www/koopjedeal/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#4 /var/www/koopjedeal/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(‘ALTER TABLE `ca…’, Array)
#5 /var/www/koopjedeal/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query(‘ALTER TABLE `ca…’, Array)
#6 /var/www/koopjedeal/lib/Varien/Db/Adapter/Pdo/Mysql.php(347): Varien_Db_Adapter_Pdo_Mysql->query(‘ALTER TABLE `ca…’)
#7 /var/www/koopjedeal/lib/Varien/Db/Adapter/Pdo/Mysql.php(2731): Varien_Db_Adapter_Pdo_Mysql->raw_query(‘ALTER TABLE `ca…’)
#8 /var/www/koopjedeal/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(815): Varien_Db_Adapter_Pdo_Mysql->addForeignKey(‘FK_CAT_PRD_FLAT…’, ‘catalog_product…’, ‘entity_id’, ‘catalog_product…’, ‘entity_id’, ‘CASCADE’, ‘CASCADE’)
#9 /var/www/koopjedeal/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.php(1389): Mage_Catalog_Model_Resource_Product_Flat_Indexer->prepareFlatTable(1)
#10 /var/www/koopjedeal/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296): Mage_Catalog_Model_Resource_Product_Flat_Indexer->reindexAll()
#11 /var/www/koopjedeal/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(350): Mage_Catalog_Model_Product_Flat_Indexer->reindexAll()
#12 /var/www/koopjedeal/app/code/core/Mage/Index/Model/Process.php(212): Mage_Catalog_Model_Product_Indexer_Flat->reindexAll()
#13 /var/www/koopjedeal/app/code/core/Mage/Index/Model/Process.php(260): Mage_Index_Model_Process->reindexAll()
#14 /var/www/koopjedeal/shell/indexer.php(167): Mage_Index_Model_Process->reindexEverything()
#15 /var/www/koopjedeal/shell/indexer.php(215): Mage_Shell_Compiler->run()
#16 {main}
|
Turns out this problem was caused by products which were deleted but still existed in the product flat data table.
To find these products you can run this query:
0
1
2
3
|
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 )
|
In this case it was nearly 80 products! To fix it you can just delete them with this query:
0
1
2
3
|
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 )
|
Revisions
- August 25, 2015 @ 18:52:09 [Current Revision] by admin
- August 25, 2015 @ 18:52:09 by admin
No comments yet.