Skip to content

Magento Error creating orders – UNQ_SALES_FLAT_INVOICE_INCREMENT_ID

Error: exception ‘PDOException’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘100000001’ for key ‘UNQ_SALES_FLAT_INVOICE_INCREMENT_ID”

We have seen errors caused like this before when people have manually copied order tables from one magento install to another

SELECT * FROM eav_entity_store

select_all_from_eav_entity_store

To resolve this issue, lets check what the latest order id for this store is

SELECT increment_id FROM `sales_flat_order` WHERE store_id = 1 ORDER BY increment_id DESC LIMIT 0, 1

select_all_from_eav_entity_store-check

 

 

The table eav_entity store must have the following records for each store

UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = ‘100000001’ WHERE store_id = 1 AND entity_type_id = 1; # customers
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = ‘100000001’ WHERE store_id = 1 AND entity_type_id = 5; # orders
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = ‘100000001’ WHERE store_id = 1 AND entity_type_id = 6; # invoices
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = ‘100000001’ WHERE store_id = 1 AND entity_type_id = 7; # creditmemos
UPDATE eav_entity_store SET increment_prefix = 1, increment_last_id = ‘100000001’ WHERE store_id = 1 AND entity_type_id = 8; # shipments

 

You need to make sure the increment id is the latest for each section

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *