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

Integrity constraint violation when adding product to cart. 
 
Rico van de Vin
Jr. Member
 
Total Posts:  14
Joined:  2010-10-11
 

Hi all,

I have a serious issue with a Magento installation. I cannot add any product to the cart. It’s a multi-website multi-store configuration and the problem occurs in all stores.

In the exception.log the following lines appear when trying to add a product to the cart:

2011-01-13T15:06:33+00:00 DEBUG (7): Exception message: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`db031624_magento`.`sales_flat_quote_address`, CONSTRAINT `FK_SALES_QUOTE_ADDRESS_SALES_QUOTE` FOREIGN KEY (`quote_id`) REFERENCES `sales_flat_quote` (`entity_id`) ON DELETE CASCADE ON UPDATE )
Trace: #0 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Adapter/Abstract.php(468): Zend_Db_Statement->execute(Array)
#2 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(’INSERT INTO `sa...’, Array)
#3 /home/users/supfjftp/superfeier.de/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query(’INSERT INTO `sa...’, Array)
#4 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Adapter/Abstract.php(546): Varien_Db_Adapter_Pdo_Mysql->query(’INSERT INTO `sa...’, Array)
#5 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(414): Zend_Db_Adapter_Abstract->insert(’sales_flat_quot...’, Array)
#6 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/Abstract.php(306): Mage_Core_Model_Mysql4_Abstract->save(Object(Mage_Sales_Model_Quote_Address))
#7 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php(500): Mage_Core_Model_Abstract->save()
#8 /home/users/supfjftp/superfeier.de/app/code/local/Mage/Sales/Model/Quote.php(201): Mage_Core_Model_Mysql4_Collection_Abstract->save()
#9 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/Abstract.php(307): Mage_Sales_Model_Quote->_afterSave()
#10 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Checkout/Model/Cart.php(357): Mage_Core_Model_Abstract->save()
#11 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Checkout/controllers/CartController.php(184): Mage_Checkout_Model_Cart->save()
#12 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_CartController->addAction()
#13 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch(’add’)
#14 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Varien/Front.php(177): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#15 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/App.php(304): Mage_Core_Controller_Varien_Front->dispatch()
#16 /home/users/supfjftp/superfeier.de/app/Mage.php(596): Mage_Core_Model_App->run(Array)
#17 /home/users/supfjftp/superfeier.de/index.php(78): Mage::run(’’, ‘store’)
#18 {main}
2011-01-13T15:06:33+00:00 ERR (3):
exception ‘Zend_Db_Statement_Exception’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘1’ for key ‘PRIMARY’’ in /home/users/supfjftp/superfeier.de/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
#0 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Adapter/Abstract.php(468): Zend_Db_Statement->execute(Array)
#2 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(’INSERT INTO `lo...’, Array)
#3 /home/users/supfjftp/superfeier.de/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query(’INSERT INTO `lo...’, Array)
#4 /home/users/supfjftp/superfeier.de/lib/Zend/Db/Adapter/Abstract.php(546): Varien_Db_Adapter_Pdo_Mysql->query(’INSERT INTO `lo...’, Array)
#5 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Log/Model/Mysql4/Visitor.php(196): Zend_Db_Adapter_Abstract->insert(’log_quote’, Array)
#6 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Log/Model/Mysql4/Visitor.php(88): Mage_Log_Model_Mysql4_Visitor->_saveQuoteInfo(Object(Mage_Log_Model_Visitor))
#7 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/Mysql4/Abstract.php(422): Mage_Log_Model_Mysql4_Visitor->_afterSave(Object(Mage_Log_Model_Visitor))
#8 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/Abstract.php(306): Mage_Core_Model_Mysql4_Abstract->save(Object(Mage_Log_Model_Visitor))
#9 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Log/Model/Visitor.php(170): Mage_Core_Model_Abstract->save()
#10 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/App.php(1228): Mage_Log_Model_Visitor->saveByRequest(Object(Varien_Event_Observer))
#11 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/App.php(1209): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Log_Model_Visitor), ‘saveByRequest’, Object(Varien_Event_Observer))
#12 /home/users/supfjftp/superfeier.de/app/Mage.php(416): Mage_Core_Model_App->dispatchEvent(’controller_acti...’, Array)
#13 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Varien/Action.php(526): Mage::dispatchEvent(’controller_acti...’, Array)
#14 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Front/Action.php(70): Mage_Core_Controller_Varien_Action->postDispatch()
#15 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Varien/Action.php(422): Mage_Core_Controller_Front_Action->postDispatch()
#16 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch(’add’)
#17 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Controller/Varien/Front.php(177): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#18 /home/users/supfjftp/superfeier.de/app/code/core/Mage/Core/Model/App.php(304): Mage_Core_Controller_Varien_Front->dispatch()
#19 /home/users/supfjftp/superfeier.de/app/Mage.php(596): Mage_Core_Model_App->run(Array)
#20 /home/users/supfjftp/superfeier.de/index.php(78): Mage::run(’’, ‘store’)
#21 {main}

The stores are under development but I cannot relate this issue to any modification of the configuration. Everything was working fine until yesterday in the afternoon.

I tried several things to solve the issue but without any success. I have been searching the web for 5 hours now but no solution found.

I tried modifying Magento core according to topic http://www.magentocommerce.com/boards/viewthread/178371/ (seemed to be a similar problem). No result.

I also truncated all sales_flat_qoute_ tables without any result.

I’m really hoping that someone here has a clue about how to solve this issue!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico van de Vin
Jr. Member
 
Total Posts:  14
Joined:  2010-10-11
 

The problem still exists.

I used the db repair tool but that tool didn\’t report any problems with the database.

I found out the same error occurs when I try to add an orders in the admin.

Can it do any harm to some part of Magento when I remove the FK_SALES_QUOTE_ADDRESS_SALES_QUOTE from the database? It\’s maybe not the best solutions but there is a great pressure the launch the shops at the end of the weekend.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Turnkeye
Enthusiast
 
Avatar
Total Posts:  908
Joined:  2008-12-20
URL: turnkeye.com
 

It seems that the database table type is not set to InnoDB.

Please try to transform it to InnoDB format.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico van de Vin
Jr. Member
 
Total Posts:  14
Joined:  2010-10-11
 

I’ll check that and give it a try, thank you. But it might be worth mentioning that everything has been functioning very well and all of a sudden the problem occurred.

EDIT: I have checked database table types and both sales_flat_quote and sales_flat_quote_address are InnoDB tables.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico van de Vin
Jr. Member
 
Total Posts:  14
Joined:  2010-10-11
 

Desperately I have remove the foreign key constraint on sales_flat_quote_address from the database. But I still cannot add items to the cart. The same problem now occurs on sales_flat_quote_item. I guess the problem is on sales_flat_quote…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico van de Vin
Jr. Member
 
Total Posts:  14
Joined:  2010-10-11
 

At last I solved the problem by removing a file from a third party module. I’m now going to contact the vendor of that module. Thanks to the contributors to this topic for their efforts.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazyguru
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2010-02-23
California, USA
 

What custom modules do you have installed?  I’ve seen this before with a module that had an error in the code causing the quote object (or parts of it) to be created more than once.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico van de Vin
Jr. Member
 
Total Posts:  14
Joined:  2010-10-11
 

The custom module was Afterpay created by Total Internet Group (Total_Afterpay).

 
Magento Community Magento Community
Magento Community
Magento Community
 
Turnkeye
Enthusiast
 
Avatar
Total Posts:  908
Joined:  2008-12-20
URL: turnkeye.com
 
Rico van de Vin - 17 January 2011 03:22 AM

The custom module was Afterpay created by Total Internet Group (Total_Afterpay).

Have you already send a note to module developers about this bug?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Rico van de Vin
Jr. Member
 
Total Posts:  14
Joined:  2010-10-11
 

Module developers are investigating the problem.

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