Magento - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry


In Magento, the error  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1246-0-2-572' for key 'PRIMARY' comes often when the catalog grows at some extent, say more than 5K SKUs and the server is not configured well OR has low resource availability. 
The server sometimes stops working because of high traffic or whatever reason and at the same time admin tries to save product.

The most possible reason is when you were about to save a product the server might stopped working due to some reason and the database transactions were not committed entirely.
So some data in the database are not matching OR the data saved but the autoincrement was not settled.

Solution:
In the error the entry string can narrow down the debugging. Here in the error the string is '1246-0-2-572'. So, 1246 gonna be the entity ID of the erroneous product.

Step 1: Find the product with ID 1246 and open it. Press all the tabs on the product information form to make the information available in future.

Step 2: In a new browser tab / window delete the product with ID 1246.

Step 3: Re-index all the indices.

Step 4: 'Add Product' with the information which was left open during Step 1.

The error should be resolved. If you're still getting the error try to follow the steps again, but exclude the Upsell, Cross sell, Custom Options and Associated Products information. Repeatedly doing this you could find the exact sub-entity of the product which causes the error. 

There may be other reasons, too, which cause the error. For the error which contains four key entries (here 1246-0-2-572 : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1246-0-2-572' for key 'PRIMARY) in the error log is most probably related with the Price index.