cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 unique constraint violation found when generating invoice

SOLVED
Highlighted

Magento 2 unique constraint violation found when generating invoice

Hi,

 

I hope someone can help me out with my issue. After updating my theme and also a couple of modules, i’ve an problem when generating invoices. 

I get the following error: “unique constraint violation found” by every way to generate an invoice, i’ve tried by the following ways. (Automatic by PSP feedback(as usual), manually, by POS plugin)


I’ve read a couple of posts it has to do with duplicates in the DB, but I cant find any in the tables i read about.

 

I would like to hear some possible solutions. Thanks!

 

Details:

Magento CE2.3.3 hosted on Byte Grow Platform

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Magento 2 unique constraint violation found when generating invoice

Hi @kai_ahnendorp 

It may be because of the issue with invoice related database entry like for example with the invoice increment id in main 'sales_invoice'. Suppose a case where system tries to enter next invoice id 100000001 and if 100000001 is already available in the table, then this issue will come.

please check with sales_invoice table and same with sales_order for check increment id. 
It may help you to resolve issue.

If issue resolve, please click on 'Kudos' & Accept as Solution!

View solution in original post

3 REPLIES 3
Highlighted

Re: Magento 2 unique constraint violation found when generating invoice

@kai_ahnendorp 

 

Found one solution but never tried this:

Just go to data base -> sales_invoice -> indexes just remove one rule "SALES_INVOICE_INCREMENT_ID_STORE_ID '

 

Please take a backup of your DB.

 

Or

 

have update all order,invoice,shipment invoice tables.

 

sequence_shipment_0,sequence_shipment_1,sequence_invoice_0,sequence_invoice_1 tables.

alter sequence_value column with auto increment primary key . and insert dummy 1 to 5 values. After that i have clean cache and every order , shipment and invoice generated ..

sequence_shipment_0

 

https://community.magento.com/t5/Magento-2-x-Technical-Issues/Unique-constraint-violation-found-afte...

Manish Mittal
https://www.manishmittal.com/
Highlighted

Re: Magento 2 unique constraint violation found when generating invoice

Hi @kai_ahnendorp 

It may be because of the issue with invoice related database entry like for example with the invoice increment id in main 'sales_invoice'. Suppose a case where system tries to enter next invoice id 100000001 and if 100000001 is already available in the table, then this issue will come.

please check with sales_invoice table and same with sales_order for check increment id. 
It may help you to resolve issue.

If issue resolve, please click on 'Kudos' & Accept as Solution!

View solution in original post

Highlighted

Re: Magento 2 unique constraint violation found when generating invoice

This has solved the problem, thanks!

 

On the tables sales_invoice and sales_order table in the DB I've changed the AUTO_INCREMENT under the Operations tab to an high value I never used for sure, and without further actions e.g. cleaning cache or reindexing, this solved the problem. 

 

Kind regards.