Preconditions (*)
- 2.2.6
- Allow guest checkout
- Have a coupon you can use
Steps to reproduce (*)
- Checkout as a guest using a valid coupon
- After placing the order, register an account using the create account button on the order confirmation page.
- Login to the admin
- Make sure to get the order to a processing state.
- Try to cancel the order
Expected result (*)
- The order is canceled
Actual result (*)
- You receive the generic errror “You have not canceled the item”
- The underlying error is:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mage`.`salesrule_customer`, CONSTRAINT `SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE), query was: INSERT INTO `salesrule_customer` () VALUES () {"exception":"[object] (Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mage`.`salesrule_customer`, CONSTRAINT `SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE), query was: INSERT INTO `salesrule_customer` () VALUES () at /www/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`mage`.`salesrule_customer`, CONSTRAINT `SALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE) at /www/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"} []
Related Issues
https://github.com/magento/magento2/issues/16779
i am still having this issue in magento 2.3.3 CE:
[2020-01-03 10:42:12] main.CRITICAL: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
xxxx.salesrule_customer, CONSTRAINTSALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_IDFOREIGN KEY (rule_id) REFERENCESsalesrule(rule_id) ON DELETE CASCADE), query was: INSERT INTOsalesrule_customer() VALUES () {“exception”:“[object] (Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (xxxx.salesrule_customer, CONSTRAINTSALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_IDFOREIGN KEY (rule_id) REFERENCESsalesrule(rule_id) ON DELETE CASCADE), query was: INSERT INTOsalesrule_customer() VALUES () at /var/www/html/magento2/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (dbzn3lqcchilq.salesrule_customer, CONSTRAINTSALESRULE_CUSTOMER_RULE_ID_SALESRULE_RULE_IDFOREIGN KEY (rule_id) REFERENCESsalesrule(rule_id) ON DELETE CASCADE) at /var/www/html/magento2/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)”} []This issue still exists on Magento 2.4.2
This issue still exist on Magento 2.4.3-p1