cancel
Showing results for 
Search instead for 
Did you mean: 

Unique constraint violation found when adding subcategory

SOLVED
Highlighted

Unique constraint violation found when adding subcategory

While adding subcategory getting error - Unique constraint violation found 

 

In Error log found this -

[2020-06-19 13:28:54] main.CRITICAL: Unique constraint violation found {"exception":"[object] (Magento\\Framework\\Exception\\AlreadyExists Exception(code: 0): Unique constraint violation found at /srv/public_html/vendor/magento/framework/EntityManager/Operation/Update.php:121, Magento\\Framework\\DB\\Adapter\\DuplicateException(code: 1062): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '433-7281' for key 'CATALOG_CATEGORY_PRODUCT_CATEGORY_ID_PRODUCT_ID', query was: INSERT INTO `catalog_category_product` (`category_id`,`product_id`,`position`) VALUES (?, ?, ?), (?, ?, ?) at /srv/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 '433-7281' for key 'CATALOG_CATEGORY_PRODUCT_CATEGORY_ID_PRODUCT_ID', query was: INSERT INTO `catalog_category_product` (`category_id`,`product_id`,`position`) VALUES (?, ?, ?), (?, ?, ?) at /srv/public_html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '433-7281' for key 'CATALOG_CATEGORY_PRODUCT_CATEGORY_ID_PRODUCT_ID' at /srv/public_html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)"} []

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Unique constraint violation found when adding subcategory

Hi @akshaykamba454 

 

Please check with your custom module, is there any observer event you are using which can trigger after save subcategory like :

"catalog_product save_commit_after"

 which may have some bug and generate error. To fix this, you can removed the bug from my custom module.

Another way to resolve, open the "catalog_product_entity" table in phpmyadmin and remove the record with the key mentioned in the exception error . 

 

It may help you to resolve issue.

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

View solution in original post

2 REPLIES 2
Highlighted

Re: Unique constraint violation found when adding subcategory

Hi @akshaykamba454 

 

Please check with your custom module, is there any observer event you are using which can trigger after save subcategory like :

"catalog_product save_commit_after"

 which may have some bug and generate error. To fix this, you can removed the bug from my custom module.

Another way to resolve, open the "catalog_product_entity" table in phpmyadmin and remove the record with the key mentioned in the exception error . 

 

It may help you to resolve issue.

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

View solution in original post

Highlighted

Re: Unique constraint violation found when adding subcategory

Thanks for your reply. 

I tried by deleting entries from table catalog_product_entity but still getting an error while saving category.