Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

(Solved) SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`dpotter_esds/catalog
 
Dunc
Member
 
Avatar
Total Posts:  56
Joined:  2008-08-05
 

If anybody can help with this error it would be appreciated. I have updated to 1.2.1.1 after several attempts, during one of those attempts I followed the solution to overcome another database error which I think might now be causing this one. The installation all went ok but if I make any changes in the Inventory section of Configuration, this error appears…

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`dpotter_esds/cataloginventory_stock_status`, CONSTRAINT `FK_CATALOGINVENTORY_STOCK_STATUS_PRODUCT` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCA)

The table cataloginventory_stock_status is empty, is that correct? If this can’t be fixed is there a way to just show all products as available as I do not use stock levels, currently the site is showing all products as out of stock, any help would be appreciated.

Thanks
Duncan

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dunc
Member
 
Avatar
Total Posts:  56
Joined:  2008-08-05
 

Is anybody able to reply to this? I’m fearing I’m going to have to re-enter all my products but I wondered if there was a query I could run on MySQL?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dunc
Member
 
Avatar
Total Posts:  56
Joined:  2008-08-05
 

No idea how but the table catalog_product_entity was not InnoDB, changing that fixed the problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
harry12bar
Sr. Member
 
Avatar
Total Posts:  168
Joined:  2008-01-07
 

Hi, Have same strange problem… can u let me know what you did in phpmyadmin… Thx

 
Magento Community Magento Community
Magento Community
Magento Community
 
tommmyboy
Jr. Member
 
Total Posts:  6
Joined:  2008-08-13
 

I experience the same problem after updating to 1.1.3

Error in file"C:\xampp\htdocs\app\code\core\Mage\CatalogInventory\sql\cataloginventory_setup\mysql4-upgrade-0.7.4-0.7.5.php" SQLSTATE[HY000]General error1452 Cannot add or update a child rowa foreign key constraint fails (`magento`.`cataloginventory_stock_status`, CONSTRAINT `FK_CATALOGINVENTORY_STOCK_STATUS_PRODUCTFOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE )
Trace:
#0 C:\xampp\htdocs\app\code\core\Mage\Core\Model\Resource\Setup.php(292): Mage::exception('Mage_Core', 'Error in file: ...')
#1 C:\xampp\htdocs\app\code\core\Mage\Core\Model\Resource\Setup.php(179): Mage_Core_Model_Resource_Setup->_modifyResourceDb('upgrade', '0.7.4', '0.7.5')
#2 C:\xampp\htdocs\app\code\core\Mage\Core\Model\Resource\Setup.php(146): Mage_Core_Model_Resource_Setup->_upgradeResourceDb('0.7.4', '0.7.5')
#3 C:\xampp\htdocs\app\code\core\Mage\Core\Model\Resource\Setup.php(121): Mage_Core_Model_Resource_Setup->applyUpdates()
#4 C:\xampp\htdocs\app\code\core\Mage\Core\Model\Config.php(205): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#5 C:\xampp\htdocs\app\code\core\Mage\Core\Model\App.php(242): Mage_Core_Model_Config->init(Array)
#6 C:\xampp\htdocs\app\Mage.php(432): Mage_Core_Model_App->init('', 'store', Array)
#7 C:\xampp\htdocs\app\Mage.php(453): Mage::app('', 'store', Array)
#8 C:\xampp\htdocs\index.php(52): Mage::run()
#9 {main}

I followed the instructions of this post first:
drop table if exist
then I tried the innodb-fix
but no change. can anyone help me?
thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Appmerce
Guru
 
Avatar
Total Posts:  376
Joined:  2008-05-13
Amsterdam, The Netherlands
 

I had the same problem. In my case multiple tables were not INNODB. I activated the Exception.log file through Developer config menu. This way I could see which tables were messed up.

I changed to INNODB:
1. cataloginventory_stock
2. core_website
3. catalog_product_entity

Then dropped and rebuilt cataloginventory_stock_Status

Everything working!

 
Magento Community Magento Community
Magento Community
Magento Community
 
envisionweb
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2008-11-16
Orlando, FL
 

Once again, another problem out of the “BLUE” after cart has been working fine for some time, no doubt a result from the “upgrade” to most recent update.  I am having the same problem and it occurs when I try to go into an order and edit it. I have successfully edited orders in the past. Not sure why all of a sudden this error is occurring. All the tables last poster names that he said he changed to InnoDB are already currently set correctly. Here is my error:

SQLSTATE[23000]Integrity constraint violation1452 Cannot add or update a child rowa foreign key constraint fails (`mydatabase_mydatabase/sales_flat_quote_payment`, CONSTRAINT `FK_SALES_QUOTE_PAYMENT_SALES_QUOTEFOREIGN KEY (`quote_id`) REFERENCES `sales_flat_quote` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCA)
Trace:
#0 /home/mydatabase/public_html/lib/Zend/Db/Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/mydatabase/public_html/lib/Zend/Db/Adapter/Abstract.php(457): Zend_Db_Statement->execute(Array)
#2 /home/mydatabase/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(230): Zend_Db_Adapter_Abstract->query('INSERT INTO `sa...', Array)
#3 /home/mydatabase/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(281): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `sa...', Array)
#4 /home/mydatabase/public_html/lib/Zend/Db/Adapter/Abstract.php(535): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `sa...', Array)
#5 /home/mydatabase/public_html/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(369): Zend_Db_Adapter_Abstract->insert('sales_flat_quot...', Array)
#6 /home/mydatabase/public_html/app/code/core/Mage/Core/Model/Abstract.php(251): Mage_Core_Model_Mysql4_Abstract->save(Object(Mage_Sales_Model_Quote_Payment))
#7 /home/mydatabase/public_html/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php(209): Mage_Core_Model_Abstract->save()
#8 /home/mydatabase/public_html/app/code/core/Mage/Sales/Model/Quote.php(218): Mage_Core_Model_Mysql4_Collection_Abstract->save()
#9 /home/mydatabase/public_html/app/code/core/Mage/Core/Model/Abstract.php(252): Mage_Sales_Model_Quote->_afterSave()
#10 /home/mydatabase/public_html/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php(231): Mage_Core_Model_Abstract->save()
#11 /home/mydatabase/public_html/app/code/core/Mage/Adminhtml/controllers/Sales/Order/EditController.php(57): Mage_Adminhtml_Model_Sales_Order_Create->initFromOrder(Object(Mage_Sales_Model_Order))
#12 /home/mydatabase/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(376): Mage_Adminhtml_Sales_Order_EditController->startAction()
#13 /home/mydatabase/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(248): Mage_Core_Controller_Varien_Action->dispatch('start')
#14 /home/mydatabase/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(158): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#15 /home/mydatabase/public_html/app/Mage.php(459): Mage_Core_Controller_Varien_Front->dispatch()
#16 /home/mydatabase/public_html/index.php(90): Mage::run()
#17 {main}

To be sure, I am using the very latest Magento release as: Magento ver. 1.3.2.1

I wish someone could PLEASE help with a solution!

 
Magento Community Magento Community
Magento Community
Magento Community
 
envisionweb
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2008-11-16
Orlando, FL
 

Why does the heading say SOLVED!!!  Its NOT solved!

 
Magento Community Magento Community
Magento Community
Magento Community
 
elfling
Enthusiast
 
Avatar
Total Posts:  901
Joined:  2008-10-21
 

Experiencing same problem now.. Whenever go to edit order.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rome2ng
Jr. Member
 
Total Posts:  18
Joined:  2009-05-20
 

i think this is shit.

Magento lack of support is the greatest turn off of the ecommerce system

i just dun understand no one is helping

experience the problemt oo

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`treoocom_gzRVKma/qkw5_sales_flat_quote_payment`, CONSTRAINT `FK_SALES_QUOTE_PAYMENT_SALES_QUOTE` FOREIGN KEY (`quote_id`) REFERENCES `qkw5_sales_flat_quote` (`entity_id`) ON DELETE CASCADE ON)

 
Magento Community Magento Community
Magento Community
Magento Community
 
PCProffitt
Jr. Member
 
Total Posts:  4
Joined:  2009-07-10
Suwanee, GA, USA
 

Answer is in this post: http://www.magentocommerce.com/boards/viewthread/32194/

 
Magento Community Magento Community
Magento Community
Magento Community
 
hidonet
Member
 
Avatar
Total Posts:  52
Joined:  2008-03-25
Istanbul
 

I’ve solved this problem with removing table prefixes.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ClemFlip
Jr. Member
 
Total Posts:  6
Joined:  2010-12-29
 

Hi Hidayet,

Can you explain how to removing table prefixes as you suggest to fix the problem.

I have been looking for solution on this forum, but nothing seems to work for me !

Thanks a lot

 
Magento Community Magento Community
Magento Community
Magento Community
 
ladle
Sr. Member
 
Avatar
Total Posts:  173
Joined:  2009-06-11
 

Just rename your tables in phpMyAdmin to not have prefixes.

 
Magento Community Magento Community
Magento Community
Magento Community
 
affect
Jr. Member
 
Avatar
Total Posts:  2
Joined:  2011-09-01
 

I had the same issue after using my Sample Data Prefix script that modifies sample data dump and adds prefixes.

Turned out I forgot to add prefixes to REFERENCES statements.

If you are using prefixes in your Magento installation, dump your database and check every operation that has “REFERENCES” in it.

Most likely you lack table prefix in it, e.g. have

REFERENCES `admin_role`

instead of

REFERENCES `yourprefix_admin_role`

Adding all missing prefixes fixed my problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
muk_t
Sr. Member
 
Total Posts:  226
Joined:  2012-07-24
 

I am getting the following message on error printing after submitting product review. Please help to resolve

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
(`Myproject`.`review`, CONSTRAINT `FK_REVIEW_ENTITY_ID_REVIEW_ENTITY_ENTITY_ID` FOREIGN KEY (`entity_id`)
REFERENCES `review_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE)

Under app/etc/local.xml I have

<db>
                <
table_prefix><![CDATA[]]></table_prefix>
</
db>

How to fix the issue.I do not have any data in the review tables.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top