Fixing SQLSTATE[23000] Integrity Constraint Violation: 1062 Duplicate Entry Error

errorimportproduct

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?

Best Answer

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).