After Upgrade to Magento 2.2.2: Duplicate entry '0-0-0-0' for key 'PRIMARY', query was: INSERT INTO `salesrule_product_attribute` () VALUES ()
-
27-12-2020 - |
Question
If I Upgrade Magento from 2.1.8 to 2.2.2 and run setup:upgrade
I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-0-0-0' for key 'PRIMARY', query was: INSERT INTO `salesrule_product_attribute` () VALUES ()
If I truncate all salesrule tables it works, but I can't do this on a production environment. Is there any workaround for this issue?
Solution
The problem is in the file vendor/magento/module-sales-rule/Model/ResourceModel/Rule.php
.
The method setActualProductAttributes
inserts empty VALUES()
if $data
is empty.
This can be fixed by overriding the Model and replace
$connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);
with:
/* Use count check like this */
if(count($data) > 0 ) {
$connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange