0

We face a unique constraint violation found error when we try to save the product. When we check the attribute code '87' in the catalog_product_entity_varchar table, we see that it is the default Magento attribute for image.

Any idea how to solve this?

[2021-07-13 09:45:09] main.CRITICAL: Unique constraint violation found {"exception":"[object] (Magento\Framework\Exception\AlreadyExistsException(code: 0): Unique constraint violation found at /vendor/magento/framework/EntityManager/Operation/Update.php:121, Magento\Framework\DB\Adapter\DuplicateException(code: 1062): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '270763-87-0' for key 'catalog_product_entity_varchar.CATALOG_PRODUCT_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID', query was: INSERT INTO catalog_product_entity_varchar (attribute_id,store_id,entity_id,value) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE attribute_id = VALUES(attribute_id), store_id = VALUES(store_id), entity_id = VALUES(entity_id), value = VALUES(value) at /vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:599, Zend_Db_Statement_Exception(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '270763-87-0' for key 'catalog_product_entity_varchar.CATALOG_PRODUCT_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID', query was: INSERT INTO catalog_product_entity_varchar (attribute_id,store_id,entity_id,value) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE attribute_id = VALUES(attribute_id), store_id = VALUES(store_id), entity_id = VALUES(entity_id), value = VALUES(value) at /vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '270763-87-0' for key 'catalog_product_entity_varchar.CATALOG_PRODUCT_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID' at /vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)"}

EDIT:

Seems that when we remove the row with attribute '87', '88', '89' and '136' in the table catalog_product_entity_varchar for a product, (all attributes for the image roles, Base, Small Thumbnail and Swatch), we then can save the product again.

But then we face the issue, that we can not save the product image role as thumbnail, small image and base image anymore. Only the swatch role remains selected when the product is saved. We also tried it with a entire new simple product and face the same issue.

enter image description here

Edit 2:

We created a new attribute "test new role" with input type "Media Image" and added that to the attribute set. Uploaded a new image, selected all image roles, including this new role and saved the product. In that case "swatch" is not selected anymore, but now only the new created attribute. So I got no clue anymore, please help me out...

enter image description here

0

Seems that we hit the limit of 2147483647 for INT. So we ALTER the table catalog_product_entity_varchar with the following query;

ALTER TABLE catalog_product_entity_varchar MODIFY COLUMN value_id INT UNSIGNED AUTO_INCREMENT;

Some more info, seems to be a Magento 2 bug; https://github.com/magento/magento2/issues/28387

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.