cancel
Showing results for 
Search instead for 
Did you mean: 

M1 to M2 Migration - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

M1 to M2 Migration - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

Hi - 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?

 

 

2 REPLIES 2

Re: M1 to M2 Migration - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

Hi   @skinnybloke

The cataloginventory_stock_item table has a multiple column unique key consists of product_id and stock_id. Obviously it is named: UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID and you are violating it by inserting a duplicate record where: product_id=449 and stock_id=1.

Make sure you are not violating this rule in your new records.

Anyway you can also try to replace: $product->save(); with: $product->getResource()->save($product); (As suggested here

 

or you also try this also

delete FROM cataloginventory_stock_item 
where product_id not in(SELECT entity_id FROM catalog_product_entity)

------------------------------------------------
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

 

 

Re: M1 to M2 Migration - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

Hi syedhasen - I have tried the delete command on the source and destination tables and both return 0 records.

 

What is interesting though is that the destination table has 1,399 additional records. The source table has 16,212 records and the destination table has 17,611 records.

 

Where would I replace: $product->save(); with: $product->getResource()->save($product) ?