0

I am in the process of migrating a site from M1 to M2

I have run the following command successfully a few times:

bin/magento migrate:delta --auto /app/code/Vendor/Migration/etc/opensource-to-opensource/1.9.4.5/config.xml

The last time I ran it the following error was displayed:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1617
  3-1' for key 'CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'

Any ideas?

  • Check both Databases you may have 2 entries of same product in CATALOGINVENTORY_STOCK_ITEM table. – Ankit Mar 29 '21 at 11:32
  • Hi Ankit - I am unable to find any duplicates in either the source or destination tables. What is interesting though is that the destination table has 1,399 additional records. Source table has 16,212 records and the destination table has 17,611 records. – David Tucker Apr 06 '21 at 09:00
  • When you migrate earlier the destination table was empty right? – Ankit Apr 06 '21 at 09:51
  • I originally migrated to a new clean v2.3.5 version of Magento. I have since then done about 5 Delta migrations without any noticeable issues. I think this is the 1st time I have done a Delta migration since upgrading Magento to v2.4.2 – David Tucker Apr 07 '21 at 13:01

1 Answers1

0

Ankit has correctly identified the problem. You're evidently attempting to migrate a record into cataloginventory_stock_item with the same unique key as a record that's already there. You may want to run a diff against both tables and eliminate duplicate entries before executing your migration command.

You can review vendor/magento/module-catalog-inventory/etc/db_schema.xml for reference. This is where the unique constraint CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID is defined, and you can see it's comprised of the product_id and stock_id fields. You'll need to diff both fields since it's a composite key.

<constraint xsi:type="unique" referenceId="CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID">
<column name="product_id"/>
<column name="stock_id"/>
</constraint>
kookaburra
  • 521
  • 2
  • 9