1

I know everyone thinks this is the same question that's been posted before but I have tried the other answers

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 f     oreign key constraint fails (`Riders`.    <result 2 when explaining filename '#sql-634_21fc81'>, CONSTRAINT    `FK_CAT_PRD_FLAT_1_ENTT_ID     _CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`enti)' in /home/.sites/143/site2/web/lib/Ze         nd/Db/Statement/Pdo.php:228
Stack trace:
#0 /home/.sites/143/site2/web/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement- >execute(Array)
#1 /home/.sites/143/site2/web/lib/Varien/Db/Statement/Pdo/Mysql.php(110):  Zend_Db_Statement_Pdo->_execute(Array)
#2 /home/.sites/143/site2/web/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /home/.sites/143/site2/web/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /home/.sites/143/site2/web/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('ALTER TABLE `ca...', Arr     ay)
#5 /home/.sites/143/site2/web/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLE `ca...',      Array)
#6 /home/.sites/143/site2/web/lib/Varien/Db/Adapter/Pdo/Mysql.php(340): Varien_Db_Adapter_Pdo_Mysql->query('ALTER TABLE `ca...')
#7 /home/.sites/143/site2/web/lib/Varien/Db/Adapter/Pdo/Mysql.php(2569): Varien_Db_Adapter_Pdo_Mysql->raw_query('ALTER TABLE `ca..     .')
#8 /home/.sites/143/site2/web/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.p    hp(816): Varien_Db_Adapter_Pdo_Mysql     ->addForeignKey('FK_CAT_PRD_FLAT...',   'catalog_product...', 'entity_id', 'catalog_product...', 'entity_id', 'CASCADE', 'CASCADE')
#9 /home/.sites/143/site2/web/app/code/core/Mage/Catalog/Model/Resource/Product/Flat/Indexer.p    hp(1390): Mage_Catalog_Model_Resourc     e_Product_Flat_Indexer->prepareFlatTable(1)
#10  /home/.sites/143/site2/web/app/code/core/Mage/Catalog/Model/Product/Flat/Indexer.php(296):    Mage_Catalog_Model_Resource_Product     _Flat_Indexer->reindexAll()
#11 /home/.sites/143/site2/web/app/code/core/Mage/Catalog/Model/Product/Indexer/Flat.php(336):  Mage_Catalog_Model_Product_Flat_Ind     exer->reindexAll()
#12 /home/.sites/143/site2/web/app/code/core/Mage/Index/Model/Process.php(209): Mage_Catalog_Model_Product_Indexer_Flat->reindexAl     l()
#13 /home/.sites/143/site2/web/app/code/core/Mage/Index/Model/Process.php(255): Mage_Index_Model_Process->reindexAll()
#14 /home/.sites/143/site2/web/shell/indexer.php(158): Mage_Index_Model_Process->reindexEverything()
#15 /home/.sites/143/site2/web/shell/indexer.php(198): Mage_Shell_Compiler->run()
#16 {main}

I removed all rows that existed in catalog product entity but not in catalog category product. I ran the database repair tool as well. It says that my database is not corrupted. I also tried truncating the table. None of those has resolved the problem.

At the moment my catalog_product_flat table is empty.

I'm not sure what else to try but I really need to correct this error to move on to the next part of my project. I'd be more than happy to start from scratch but this is a live site with live products and orders going on.

Any advice or help would be extremely appreciated.

5
  • It tells you that one certain foreign key constraint fails... Try finding out what this constraint does en check the query you are performing (by activating the query logging). You will find that one of the tables doesn't have a row where there should be one... Aug 9, 2013 at 16:03
  • yeah my catalog product flat table has no rows, other than that I have no idea
    – TwoEyedDan
    Aug 9, 2013 at 17:23
  • Try repairing your tables magentocommerce.com/wiki/1_-_installation_and_configuration/… Aug 9, 2013 at 21:10
  • Ok I already tried the database repair tool and also I've tried truncating the catalog_product_flat_1 and it does not correct the error
    – TwoEyedDan
    Aug 11, 2013 at 2:40
  • Could someone give me the SQL to copy everything in catalog_product_entity into catalog_product_flat ?
    – TwoEyedDan
    Aug 11, 2013 at 2:41

2 Answers 2

4
  1. Delete any locks you have in var/locks/
  2. In the database, drop all the tables that start with catalog_product_flat_
  3. In the terminal (command line), cd to shell folder
  4. Run php indexer.php --reindexall
1
  • Followed this, and it saved my bacon. Or Quorn sausages if you're vegetarian. Thank you! Jun 28, 2017 at 10:13
4
  1. Truncate:

    • catalog_product_flat_1
    • catalog_product_flat_2
    • catalog_product_flat_3
    • catalog_product_flat_cl
  2. Reindex manually: php /yoursite/shell/indexer.php --reindexall

Greetings.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.