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

Unable to create Sales or Catalog price rules
 
KooTjoo
Jr. Member
 
Total Posts:  14
Joined:  2012-03-09
 

Out of the blue I am experiencing the following problem. When I try to set a Price Rule I receive the following error in Magento: An error occurred while saving the rule data. Please review the log and try again.

The exception log shows the following error:

2013-05-02T08:59:14+00:00 ERR (3):
exception ‘PDOException’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mywebsite_db`.`salesrule_customer_group`, CONSTRAINT `FK_SALESRULE_CSTR_GROUP_CSTR_GROUP_ID_CSTR_GROUP_CSTR_GROUP_ID` FOREIGN KEY (`customer_group_id`) REFERENCES `customer_group` (`cu)’ in /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#4 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(’INSERT INTO `sa...’, Array)
#5 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query(’INSERT INTO `sa...’, Array)
#6 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/lib/Varien/Db/Adapter/Pdo/Mysql.php(1910): Varien_Db_Adapter_Pdo_Mysql->query(’INSERT INTO `sa...’, Array)
#7 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Rule/Model/Resource/Abstract.php(137): Varien_Db_Adapter_Pdo_Mysql->insertOnDuplicate(’salesrule_custo...’, Array, Array)
#8 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/SalesRule/Model/Resource/Rule.php(124): Mage_Rule_Model_Resource_Abstract->bindRuleToEntity(’38’, Array, ‘customer_group’)
#9 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(463): Mage_SalesRule_Model_Resource_Rule->_afterSave(Object(Mage_SalesRule_Model_Rule))
#10 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Core/Model/Abstract.php(318): Mage_Core_Model_Resource_Db_Abstract->save(Object(Mage_SalesRule_Model_Rule))
#11 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Adminhtml/controllers/Promo/QuoteController.php(163): Mage_Core_Model_Abstract->save()
#12 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Adminhtml_Promo_QuoteController->saveAction()
#13 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch(’save’)
#14 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#15 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#16 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#17 /var/www/vhosts/mywebsite.nl/httpdocs/mywebsite/index.php(139): Mage::run(’view_hetspeelgo...’)
#18 {main}

A week ago it worked great and I made a new coupon code, what can have gone wrong? I have reindexed all but no luck so far.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jccarlin
Jr. Member
 
Total Posts:  2
Joined:  2012-05-22
 

I realize this is an old post.. were you ever able to resolve it? I am having the exact same issue. I believe it is related to an extension we previously had installed.. now when trying to save a rule we get the same error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`ccofruit_magento`.`catalogrule_product`, CONSTRAINT `FK_CATALOGRULE_PRODUCT_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON DELETE C)

Trace:
#0 /hostinglarge/ccofruit/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /hostinglarge/ccofruit/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /hostinglarge/ccofruit/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#3 /hostinglarge/ccofruit/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(’INSERT INTO `ca...’, Array)
#4 /hostinglarge/ccofruit/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query(’INSERT INTO `ca...’, Array)
#5 /hostinglarge/ccofruit/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(1974): Varien_Db_Adapter_Pdo_Mysql->query(’INSERT INTO `ca...’, Array)
#6 /hostinglarge/ccofruit/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(1947): Varien_Db_Adapter_Pdo_Mysql->insertArray(’catalogrule_pro...’, Array, Array)
#7 /hostinglarge/ccofruit/public_html/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php(145): Varien_Db_Adapter_Pdo_Mysql->insertMultiple(’catalogrule_pro...’, Array)
#8 [internal function]: Mage_CatalogRule_Model_Resource_Rule->updateRuleProductData(Object(Mage_CatalogRule_Model_Rule), Object(Mage_CatalogRule_Model_Rule), Object(Mage_CatalogRule_Model_Rule), Object(Mage_CatalogRule_Model_Rule))
#9 /hostinglarge/ccofruit/public_html/lib/Varien/Data/Collection.php(466): call_user_func_array(Array, Array)
#10 /hostinglarge/ccofruit/public_html/app/code/core/Mage/CatalogRule/Model/Rule.php(319): Varien_Data_Collection->walk(Array)
#11 /hostinglarge/ccofruit/public_html/app/code/core/Mage/Adminhtml/controllers/Promo/CatalogController.php(287): Mage_CatalogRule_Model_Rule->applyAll()
#12 /hostinglarge/ccofruit/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_Adminhtml_Promo_CatalogController->applyRulesAction()
#13 /hostinglarge/ccofruit/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch(’applyRules’)
#14 /hostinglarge/ccofruit/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#15 /hostinglarge/ccofruit/public_html/app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Controller_Varien_Front->dispatch()
#16 /hostinglarge/ccofruit/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#17 /hostinglarge/ccofruit/public_html/index.php(87): Mage::run(’’, ‘store’)
#18 {main}

Any help would be greatly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jccarlin
Jr. Member
 
Total Posts:  2
Joined:  2012-05-22
 

We were able to fix this. In our case we exported the effected tables: catalogrule_price and catalogrule_group - renamed these tables in the DB and then re-imported the exported tables.

Foreign keys were reset and all is well again and we removed the old tables.

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