How to Fix Unique Constraint Violation Found in Magento 2

Written by Jigar Patel

Oct 07, 2021

How to Fix Unique Constraint Violation Found in Magento 2

While saving a new product in the admin panel I am getting this error “Unique constraint violation found”

Magento 2.4.3 installation and save the product on that time not able to add any products, categories items to it. I get an error “Unique constraint violation found” when I do any of these operations. I was able to add custom product attributes and add them to attribute sets too, but am stuck after that.

You may have got an integrity constraint violation error while creating a product from the backend in Magento 2 store.

When you face this error, it means that a duplicate value is created in the database table.

In this blog you will find the solution of unique constraint violation found in magento 2 :

Unique Constraint Violation error usually occurs when adding data to a database table. The reason for the error can be the creation of duplicate values in the database table.

Here’s the solution to fix unique constraint violation in Magento 2 admin panel.

How to Fix Unique Constraint Violation Found in Magento 2

Solution:1

Table ‘catalog_product_entity‘ last inserted row id is “349580” (highest) but in table AUTO_INCREMENT value is “338897” so Exception occur.

Probably your AUTO_INCREMENT is set wrong for the table. You can check this with:

SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ‘db_name’ AND TABLE_NAME = ‘table_name’;

You can then fix the auto-increment by setting it the highest ID +1

ALTER TABLE table_name AUTO_INCREMENT = start_value;

How to Fix Unique Constraint Violation Found in Magento 2

Solution:2

Face “Unique Constraint violation found” issue  in invoice check bellow step:

SOLVED Invoice Unique Constraint Violation Magento 2.2.5 when i am generating a invoice facing this error

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

Solution:3

Face “Unique Constraint violation found” issue  in creating a new order check bellow step:

Check the table “sequence_order_1” where 1 refers to the store id.

The sequence_value column should be auto_increment to fix the integrity constraint violation in Magento 2.

That’s it this is how you can easily fix Unique Constraint Violation errors in Magento 2, All the given 3 scenarios are easy to implement

If you have any difficulties regarding this blog, do consider posting in the Comments section below! If you are looking for an expert Magento developer then you can contact us.

I’m here to help.

Thank you!

Jigar Patel

Author

We can help you with

  • Dedicated Team
  • Setup Extended Team
  • Product Development
  • Custom App Development

Schedule a Developer Interview And Get 7 Days Risk-Free Trial

Fill out This Form and one of Our Technical Experts will Contact you Within 12 Hours.

    Google
    |

    4.8

    Google
    |

    4.8

    Google
    |

    4.9

    Google
    |

    4.8

    Google
    |

    4.9

    Copyright © 2024 DOLPHIN WEB SOLUTION. All rights reserved.

    TO TOP