SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'SALES_ORDER_INCREMENT_ID_STORE_ID'

magento.stackexchange https://magento.stackexchange.com/questions/262291

Question

I am using this data-migration-tool, When i migrate from magento 1.9.3.2 to magento 2.3,getting below error,

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'SALES_ORDER_INCREMENT_ID_STORE_ID'

i tried many times upload fresh DB,still getting this issue

Was it helpful?

Solution

The error occurs if there are orders in the Magento 1 database with no increment_id set. You can check if you have such orders by running the following SQL statement in your Magento 1 database:

select count(*) from sales_flat_order where increment_id = '' OR increment_id is NULL;

If the returned value is greater than 0, you should update the tables sales_flat_order and sales_flat_order_grid in such a way to ensure that all your orders have increment_ids and those are unique.

If you find incrment_ids in the sales_flat_order_grid table for all orders, just take the values from there with the following statemen:

update sales_flat_order o 
join sales_flat_order_grid g 
    on o.entity_id = g.entity_id  
set o.increment_id = g.increment_id 
where o.increment_id = '' OR o.increment_id is NULL;

If you don't find orders without any increment_id it might be the best option to create arbitrary increment_ids. For example you can use a SQL update statement which builds an increment_id based on the entity_id and a prefix of your choice (just replace the prefix in the sample statements with something which doesn't conflict with existing increment_ids):

update sales_flat_order set increment_id = concat ('990000', entity_id) where increment_id is null;
update sales_flat_order_grid set increment_id = concat ('990000', entity_id) where increment_id is null;
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top