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

Page 1 of 2
Integrity constraint violation: 1452 Cannot add or update a child row
 
Nimesh Patel
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2008-05-09
Ahmedabad, India
 

Hello Everyone,

i had upgrade magento to 1.3.2.1,

After upgrade when i goes to edit order it shows me an integrity constraint error,

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

Please help me to resolve this issue,

Thank You
Nimesh

 
Magento Community Magento Community
Magento Community
Magento Community
 
keatonw
Jr. Member
 
Total Posts:  1
Joined:  2009-07-10
 

I’m having the same problem, anybody know how to fix this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dave Swift
Jr. Member
 
Total Posts:  7
Joined:  2008-11-11
Boston, MA
 

I am also experiencing this issue.  Has anyone made any progress?  Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Chris Farley
Member
 
Total Posts:  43
Joined:  2008-03-09
 

I get that every time I try and edit a guest order.

I can edit orders for logged-in users no problem.

Version 1.3.2.1

We’ll be upgrading to 1.3.4 soon. Anybody know if this is fixed yet?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dave Swift
Jr. Member
 
Total Posts:  7
Joined:  2008-11-11
Boston, MA
 

@Chris Farley Thanks for posting your observation.  From that I was able to trace the root of the problem (at least mine).  I found that the problem was actually fixed in version 1.3.2.2 (from the release notes: “Fixed #13706: Edit Order SQL Error").

Now, if you don’t want to upgrade to the latest release, my early test show you can just replace one file to fix the problem. Download 1.3.2.2 and replace /app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php.  There are three blocks of code that it replaces related to the customer.

Again, I just tried this fix today so be a little cautious, but I do think it fixed the problem.  I wound be interested to hear if it worked for you or if you ran into any issues.  Thanks again.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mike222
Member
 
Total Posts:  41
Joined:  2008-04-07
Austria
 

None of the suggestions so far worked for me. I am about to upgrade from 1.1.8 right to the current version 1.3.2.4.

After examining the issue I tried the following hack which finally worked for me:

in app/code/Core / Mage / Sales / Model / Quote.php I inserted the following code in the method _afterSave() :

if (null !== $this->_payments{
           
// inserted code start
            
$this->getPaymentsCollection();
            if (
$this->getId()) {
                
foreach ($this->_payments as $payment{
                    $payment
->setQuote($this);
                
}
            }
           
// inserted code end
            
$this->getPaymentsCollection()->save();
        
}

This initializes the PaymentsCollection, reassigns the quote to each Payment and then saves it.

For reference purposes this was the exception I got when trying to add an item to the basket:

Exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`bluraymagento/sales_flat_quote_payment`, CONSTRAINT `FK_SALES_QUOTE_PAYMENT_SALES_QUOTE` FOREIGN KEY (`quote_id`) REFERENCES `sales_flat_quote` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCA)
Trace: #0 /srv/www/bluray/magento/lib/Zend/Db/Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array)
#1 /srv/www/bluray/magento/lib/Zend/Db/Adapter/Abstract.php(457): Zend_Db_Statement->execute(Array)
#2 /srv/www/bluray/magento/lib/Zend/Db/Adapter/Pdo/Abstract.php(230): Zend_Db_Adapter_Abstract->query(’INSERT INTO `sa...’, Array)
#3 /srv/www/bluray/magento/lib/Varien/Db/Adapter/Pdo/Mysql.php(281): Zend_Db_Adapter_Pdo_Abstract->query(’INSERT INTO `sa...’, Array)
#4 /srv/www/bluray/magento/lib/Zend/Db/Adapter/Abstract.php(535): Varien_Db_Adapter_Pdo_Mysql->query(’INSERT INTO `sa...’, Array)
#5 /srv/www/bluray/magento/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(369): Zend_Db_Adapter_Abstract->insert(’sales_flat_quot...’, Array)
#6 /srv/www/bluray/magento/app/code/core/Mage/Core/Model/Abstract.php(251): Mage_Core_Model_Mysql4_Abstract->save(Object(Mage_Sales_Model_Quote_Payment))
#7 /srv/www/bluray/magento/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php(221): Mage_Core_Model_Abstract->save()
#8 /srv/www/bluray/magento/app/code/core/Mage/Sales/Model/Quote.php(218): Mage_Core_Model_Mysql4_Collection_Abstract->save()
#9 /srv/www/bluray/magento/app/code/core/Mage/Core/Model/Abstract.php(252): Mage_Sales_Model_Quote->_afterSave()
#10 /srv/www/bluray/magento/app/code/core/Mage/Checkout/Model/Cart.php(340): Mage_Core_Model_Abstract->save()
#11 /srv/www/bluray/magento/app/code/core/Mage/Checkout/controllers/CartController.php(172): Mage_Checkout_Model_Cart->save()
#12 /srv/www/bluray/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(376): Mage_Checkout_CartController->addAction()
#13 /srv/www/bluray/magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(248): Mage_Core_Controller_Varien_Action->dispatch(’add’)
#14 /srv/www/bluray/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(158): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#15 /srv/www/bluray/magento/app/Mage.php(459): Mage_Core_Controller_Varien_Front->dispatch()
#16 /srv/www/bluray/magento/index.php(65): Mage::run()
#17 {main}

Hope this helps.

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

The above solution #5 works for me. It suddenly happened to a 1.3.2.4 site after 7 months without problems.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
illo_sdrawkcab
Member
 
Total Posts:  63
Joined:  2008-10-23
 

Is this still a core bug or some broken data in database? exactly this problem occurs in version 1.4.1.0.
Tried to upgrade to 1.4.1.1 but this did not help.

For me post #5 did help too.

 
Magento Community Magento Community
Magento Community
Magento Community
 
loeffel
Guru
 
Avatar
Total Posts:  427
Joined:  2009-02-03
 

Thank you, mike222. I received the same error when trying to reorder from the customer dashboard. I think this problem occured becasue I used a faulty sql query to clean up my db of logs and test orders. It is working now thanks to your code - I just hope I didn’t break anything else with the sql query that I jsut haven’t found yet..

Thanks again!

 
Magento Community Magento Community
Magento Community
Magento Community
 
loeffel
Guru
 
Avatar
Total Posts:  427
Joined:  2009-02-03
 

OK, I just couldnt live with the fact that I had to modify the core to fix something that used to work flawlessly. So I looked through my entire DB (still guessing, I had fubared it with a cleanup script) only to find out, that everything here was fine.
After a long search I finally disabled my cart rules and voila I don’t need the fix anymore. This will most likely not help everybody in here, but it may be worth a try.
Now I just have to add these rules again without causing havoc in my shop again…

So to summarize: mike’s script works, but maybe there is no need for it, if you look and test thoroughly

 
Magento Community Magento Community
Magento Community
Magento Community
 
h-a-r-v
Jr. Member
 
Total Posts:  4
Joined:  2010-08-09
 

I love you, Mike.

The scariest thing about this issue is that apparently it can happen at a random time. It happened to me yesterday, when I went to see my client to officially finish my job and show him how to manage things, hehe. Great timing. Some other ppl report they got it like after 7 months, as I can see. “Very scary, oh no!”

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaime
Sr. Member
 
Total Posts:  79
Joined:  2010-03-26
 

Thanks a lot, mike222.
I am using 1.4.1.1. and your hack did work fantastic!!

Regards
Jaime

 
Magento Community Magento Community
Magento Community
Magento Community
 
ankit_sam
Member
 
Avatar
Total Posts:  34
Joined:  2009-12-10
 

Thanks Mike, superb.

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

Hi all,

I got the same issue so I look for a solution on this forum but despite a lots of solution posted on this forum, only Mike solution seems to works.

So I tried Mike solution but it did work for me maybe because I am not sure to understand properly what \” inserted the following code in the method _afterSave()\” mean.

In fact, because I can\’t find the terme \"method _afterSave()\” in my Quote.php file, I replace :

protected function _afterSave()
{
parent::_afterSave();

if (null !== $this->_addresses) {
$this->getAddressesCollection()->save();
}

if (null !== $this->_items) {
$this->getItemsCollection()->save();
}

if (null !== $this->_payments) {
$this->getPaymentsCollection()->save();
}
return $this;
}

TO :

protected function _afterSave()
{
parent::_afterSave();

if (null !== $this->_payments) {
// inserted code start
$this->getPaymentsCollection();
if ($this->getId()) {
foreach ($this->_payments as $payment) {
$payment->setQuote($this);
}
}
// inserted code end
$this->getPaymentsCollection()->save();
}
return $this;
}

Could you please tell me if I am doing the right modification ?

Thanks a lot

 
Magento Community Magento Community
Magento Community
Magento Community
 
hammock_vienna
Member
 
Total Posts:  60
Joined:  2008-06-16
 

We get exactly the same error when the user adds a product to his shopping cart. The Shopping cart stays empty with the following error mesg “Cannot add the item to shopping cart.”

If we deactivate our shopping cart price rule everything works fine. We can add the product to the shopping cart. If we activate the shopping cart price rule again it still works. Once we delete all cookies from the browser the user can’t add products to the shopping cart anymore as long we don’t deactivate the price rule…

The shopping cart price rule is configured to work without a coupon code. If we change it to a price rule with a coupon code the error does not appear. The shopping cart price rule is configured to act only on certain sku’s if the client chooses a specific payment method.

Unfortunatly the fix in #5 does not work :-(

Any idea?

System => Configuration => WEB-Cookie Session => Cookie Lifetime: 86400

I reported that bug: http://www.magentocommerce.com/bug-tracking/issue?issue=10964

 
Magento Community Magento Community
Magento Community
Magento Community
 
redlights
Jr. Member
 
Total Posts:  15
Joined:  2011-03-02
 

Hammock,

have you suceed to fix this issue?

Tks!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2