2

I've a problem with my product import extension that is returned the "classic" violation integrity error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '25061-1' for key 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'

I'm using Magento CE 1.7.0.2.

There are multiple topics about that issue on stackoverflow, magento forums with different technical approaches like below:

  • Someone recommends to download and use the dbtools repairs provided by Magento, **.

  • Some are providing db tables list to truncate** "with no major risk".

  • An another proposal is to identify with precision the data and remove it from the related db table.

What is the pragmatic way to identify and fix that issue?

  • Check your import, be sure to load the stock item, before writing a new one – Fabian Blechschmidt May 22 '14 at 14:32
  • 1
    the problem is, you try to create a stock item with the product_id and stock_id for a product/stock which already exists. This means you have either to delete the old one before or load it, update it and then write it back – Fabian Blechschmidt May 22 '14 at 15:11
  • 1
    check wether you have a stock item with a reference on this product. If this is the case, your foreign key constraints seem to be broken – Fabian Blechschmidt May 22 '14 at 15:39
  • 1
    then I guess your import creates the stock item twice? Be creative. Golden rule: Mysql is never wrong. Or to quote spock "First try all the logical solutions. If they are all disproved, continue with the illogical" Whatever happens, magento tries to create a second stockitem, therefore there must be a first. and if everything happens in an transaction, you can't see it on the outside – Fabian Blechschmidt May 22 '14 at 16:01
  • 2
    Thank you for your help. I'll keep in mind your Golden rule ;) – DarkCowboy May 23 '14 at 6:47
3

The error has been found on our import/update script (product->save() was called twice).

Important: no database "cleaning" was required.

I'm happy to have not choose to follow some advice on the web that propose to do that kind of operations (@fabian, you're golden rule was successfully followed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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