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?

1 Answer 1


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);


/* Use count check like this */

if(count($data) > 0 ) {
    $connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.