cancel
Showing results for 
Search instead for 
Did you mean: 

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row

SOLVED

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row

Hello. I am desperate with the following error :

 

Product Attributes index process unknown error: 
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`wallshoplive`.`catalog_product_index_eav`, CONSTRAINT `FK_CAT_PRD_IDX_EAV_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE C) in /home/wpaper/public_html/lib/Zend/Db/Statement/Pdo.php:228 
Stack trace: 
#0 /home/wpaper/public_html/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array) 
#1 /home/wpaper/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array) 
#2 /home/wpaper/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array) 
#3 /home/wpaper/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array) 
#4 /home/wpaper/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array) 
#5 /home/wpaper/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array) 
#6 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(179): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...') 
#7 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Helper/Mysql4.php(49): Mage_Index_Model_Resource_Abstract->insertFromSelect(Object(Varien_Db_Select), 'catalog_product...', Array, false) 
#8 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(153): Mage_Index_Model_Resource_Helper_Mysql4->insertData(Object(Mana_Filters_Resource_Indexer_Source), Object(Varien_Db_Select), 'catalog_product...', Array, false) 
#9 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(113): Mage_Index_Model_Resource_Abstract->insertFromTable('catalog_product...', 'catalog_product...', false) 
#10 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php(54): Mage_Index_Model_Resource_Abstract->syncData() 
#11 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav.php(185): Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract->reindexAll() 
#12 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Indexer/Abstract.php(143): Mage_Catalog_Model_Resource_Product_Indexer_Eav->reindexAll() 
#13 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(212): Mage_Index_Model_Indexer_Abstract->reindexAll() 
#14 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(260): Mage_Index_Model_Process->reindexAll() 
#15 /home/wpaper/public_html/shell/indexer.php(168): Mage_Index_Model_Process->reindexEverything() 
#16 /home/wpaper/public_html/shell/indexer.php(216): Mage_Shell_Compiler->run() 
#17 {main} 

Next Zend_Db_Statement_Exception: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`wallshoplive`.`catalog_product_index_eav`, CONSTRAINT `FK_CAT_PRD_IDX_EAV_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE C), query was: INSERT INTO `catalog_product_index_eav` (`entity_id`, `attribute_id`, `store_id`, `value`) SELECT `catalog_product_index_eav_idx`.`entity_id`, `catalog_product_index_eav_idx`.`attribute_id`, `catalog_product_index_eav_idx`.`store_id`, `catalog_product_index_eav_idx`.`value` FROM `catalog_product_index_eav_idx` ON DUPLICATE KEY UPDATE `entity_id` = VALUES(`entity_id`), `attribute_id` = VALUES(`attribute_id`), `store_id` = VALUES(`store_id`), `value` = VALUES(`value`) in /home/wpaper/public_html/lib/Zend/Db/Statement/Pdo.php:235 
Stack trace: 
#0 /home/wpaper/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array) 
#1 /home/wpaper/public_html/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array) 
#2 /home/wpaper/public_html/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array) 
#3 /home/wpaper/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array) 
#4 /home/wpaper/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array) 
#5 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(179): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...') 
#6 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Helper/Mysql4.php(49): Mage_Index_Model_Resource_Abstract->insertFromSelect(Object(Varien_Db_Select), 'catalog_product...', Array, false) 
#7 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(153): Mage_Index_Model_Resource_Helper_Mysql4->insertData(Object(Mana_Filters_Resource_Indexer_Source), Object(Varien_Db_Select), 'catalog_product...', Array, false) 
#8 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Resource/Abstract.php(113): Mage_Index_Model_Resource_Abstract->insertFromTable('catalog_product...', 'catalog_product...', false) 
#9 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav/Abstract.php(54): Mage_Index_Model_Resource_Abstract->syncData() 
#10 /home/wpaper/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Eav.php(185): Mage_Catalog_Model_Resource_Product_Indexer_Eav_Abstract->reindexAll() 
#11 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Indexer/Abstract.php(143): Mage_Catalog_Model_Resource_Product_Indexer_Eav->reindexAll() 
#12 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(212): Mage_Index_Model_Indexer_Abstract->reindexAll() 
#13 /home/wpaper/public_html/app/code/core/Mage/Index/Model/Process.php(260): Mage_Index_Model_Process->reindexAll() 
#14 /home/wpaper/public_html/shell/indexer.php(168): Mage_Index_Model_Process->reindexEverything() 
#15 /home/wpaper/public_html/shell/indexer.php(216): Mage_Shell_Compiler->run() 
#16 {main}

This happening when catalog_product_attribute indexer runs. Site is working, everything seems fine.

 

Can anyone please help me?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child

Solved. Solution was running these queries. Always backup database first:

delete FROM `catalog_product_entity_datetime` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_decimal` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_gallery` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_group_price` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_int` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_media_gallery` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_text` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_tier_price` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_varchar` where entity_id not in (select entity_id from catalog_product_entity);
delete from `catalog_category_product` WHERE product_id not in(select entity_id from catalog_product_entity);
delete from `catalog_category_product` WHERE category_id not in(select entity_id from catalog_category_entity); 
delete from `catalog_product_website` WHERE product_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_index_eav_idx` WHERE entity_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_index_eav` WHERE entity_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_link` WHERE product_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_relation` WHERE parent_id not in(select entity_id from catalog_product_entity);

View solution in original post

1 REPLY 1

Re: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child

Solved. Solution was running these queries. Always backup database first:

delete FROM `catalog_product_entity_datetime` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_decimal` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_gallery` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_group_price` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_int` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_media_gallery` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_text` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_tier_price` where entity_id not in (select entity_id from catalog_product_entity);
delete FROM `catalog_product_entity_varchar` where entity_id not in (select entity_id from catalog_product_entity);
delete from `catalog_category_product` WHERE product_id not in(select entity_id from catalog_product_entity);
delete from `catalog_category_product` WHERE category_id not in(select entity_id from catalog_category_entity); 
delete from `catalog_product_website` WHERE product_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_index_eav_idx` WHERE entity_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_index_eav` WHERE entity_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_link` WHERE product_id not in(select entity_id from catalog_product_entity); 
delete from `catalog_product_relation` WHERE parent_id not in(select entity_id from catalog_product_entity);