Magento – Fix SQLSTATE[23000] Integrity Constraint Violation: Duplicate Entry

databasemagento-1.7onepage-checkoutpayment-gateway

I am using "Sage Pay" for payment transaction in magento. But when I place order it show the following error:

An sage pay error ocurred: SQLSTATE[23000]: Integrity constraint violation:1062 Duplicate entry '2000734" for key 'UNQ_SALES_FLAT_INVOICE_INCREMENT_ID'

Best Answer

To fix this issue, you need to change your increment_last_id of your invoice entity type.

By default in magento invoice entity type is 6. Which you can find in eav_entity_type table.

You need to change increment_last_id value for your store. The increment_last_id is in eav_entity_store table. You can run following query to update your invoice increment_last_id. Where X is your new increment_last_id and STORE_ID_HERE is your store id to whom you changing invoice increment_last_id.

UPDATE eav_entity_store
       INNER JOIN eav_entity_type
         ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id
SET    eav_entity_store.increment_last_id = 'X'
WHERE  eav_entity_type.entity_type_code = 'invoice'
       AND eav_entity_store.store_id = {STORE_ID_HERE};

OR

UPDATE `eav_entity_store` SET `increment_last_id` = 'X' WHERE `entity_type_id` = '6';

Notice that the value for increment_last_id already contains the increment_prefix. Use your entity_type increment_prefix

For more details check here : https://www.warpconduit.net/2012/04/18/how-to-change-the-order-increment-id-and-prefix-in-magento/

Hope it helps.

Related Topic