Magento2: Update from 2.1.9 to 2.2.0 fails with sql constraint violation on salesrule_product_attribute

Created on 20 Oct 2017  路  12Comments  路  Source: magento/magento2

Preconditions

  1. uname -a
    Linux XXX 4.4.0-96-generic #119-Ubuntu SMP Tue Sep 12 14:59:54 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  2. DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
  3. magento 2.1.9 without sample data, migrated data from 1.5 -> 1.9 -> 2.x
  4. mysql-server-5.7 (5.7.19-0ubuntu0.16.04.1) from ubuntu repository
  5. php7.0 (7.0.24-1+ubuntu14.04.1+deb.sury.org+1)
  6. (client firefox 54, but happens with other browsers, too)

Steps to reproduce

  1. With above setup, do an update via composer to 2.2.0
# set MAGENTO_USER=..... , VERSION=2.2.0
su $MAGENTO_USER -c 'composer require magento/product-community-edition $VERSION --no-update'
su $MAGENTO_USER -c 'composer update'
  1. sudo -u $MAGENTO_USER php bin/magento setup:upgrade

Expected result

Updates all fine, sun shines.

Actual result

Update fails, it rains. Truncated output:

[...]
Updating modules:
Schema creation/updates:
Module 'Magento_Store':
[...]
Module 'Magento_OfflinePayments':
Module 'Magento_SalesRule':
Upgrading data.. SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-0-0-0' for key 'PRIMARY', query was: INSERT INTO `salesrule_product_attribute` () VALUES ()

Any way to debug this any further?

Format is valid

Most helpful comment

my workaround (not sure if it causes further errors, just did it and setup:upgrade reported success)
vendor/magento/module-sales-rule/Model/ResourceModel/Rule.php line 352
$connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);

wrap it in

if (!empty($data)) {
    $connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);
}

All 12 comments

If You haven't custom sales rule, only sample-data run this Query in PhpMyAdmin

TRUNCATE TABLE salesrule;
TRUNCATE TABLE salesrule_coupon;
TRUNCATE TABLE salesrule_coupon_usage;
TRUNCATE TABLE salesrule_customer;
TRUNCATE TABLE salesrule_product_attribute;

And after run php bin/magento setup:upgrade

Hi @fwolfst
For migration related issues please use the correct repository: https://github.com/magento/data-migration-tool

Thank you.

I'm curious if you ever got this resolved, I'm seeing the same problem and no corresponding issue in the data-migration-tool repository.

@msm93v2 Afair we deleted the salesrules.

Have you found a workaround for this bug?

@TechOS-PL what if I have custom sales rules?

my workaround (not sure if it causes further errors, just did it and setup:upgrade reported success)
vendor/magento/module-sales-rule/Model/ResourceModel/Rule.php line 352
$connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);

wrap it in

if (!empty($data)) {
    $connection->insertMultiple($this->getTable('salesrule_product_attribute'), $data);
}

@asavchenko same worked for me

@bpoiss @asavchenko Could you please say if this causes unexpected behaviour along the way?

@victortodoran no it didn't cause any issues, I did this on multiple systems and it always worked for me

@asavchenko thanks for the fix, it worked for me also.

@deepikajaniyani please reply me I need help

Was this page helpful?
0 / 5 - 0 ratings