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.
See this entry in Exception Log :
[dt_code]main.CRITICAL: Unique constraint violation found {“exception”:”[object] (Magento\\Framework\\Exception\\AlreadyExistsException(code: 0): Unique constraint violation found at /vendor/magento/framework/EntityManager/Operation/Create.php:134, Magento\\Framework\\DB\\Adapter\\DuplicateException(code: 1062): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘338896’ for key ‘PRIMARY’, query was: INSERT INTO `catalog_product_entity` (`entity_id`, `attribute_set_id`, `type_id`, `sku`, `has_options`, `required_options`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?) at /public_html/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:585, Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘338896’ for key ‘PRIMARY’, query was: INSERT INTO `catalog_product_entity` (`entity_id`, `attribute_set_id`, `type_id`, `sku`, `has_options`, `required_options`, `created_at`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?) at /public_html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘338896’ for key ‘PRIMARY’ at /public_html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)”} [][/dt_code]
Unique Constraint Violation error usually occurs adding data to a database table. The reason for 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.
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;
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
Face “Unique Constraint violation found” issue in creating 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.
This way you can Fix Unique Constraint Violation errors.
If you have any difficulties regarding this blog, do consider them posting in the Comments section below!
I’m here to help.
Thank you!
In Magento
Apr 02, 2023
Do not miss a chance to grab exciting offers on Magento Development at Dolphin Web Solution. We are providing discounts on various Magento services this season. Go and grab yours today at our Magento Store.