0

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?

bpoiss
  • 13,673
  • 3
  • 35
  • 49

1 Answers1

2

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:

if(count($data > 0 )) {
    $connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);
}
bpoiss
  • 13,673
  • 3
  • 35
  • 49
  • Unable to apply data patch ... Parameter must be an array or an object that implements Countable ... Just deleting that line rather than if - seems to worked – Jon Sep 24 '20 at 07:09