0

I changed php version and composer version.But run command "bin/magento setup:upgrade", display error like this.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '584362' for key 'PRIMARY', query was: ALTER TABLE `catalog_url_rewrite_product_category` ADD CONSTRAINT  PRIMARY KEY (`url_rewrite_id`)

1 Answer 1

0

Magento added a constraint to the table catalog_url_rewrite_product_category at 2.4.3 I think.

You won't be able to bin/magento setup:upgrade without solving the issue. Composer is not at fault.

The fix is pretty easy.

Take full backup of your database first and execute this SQL query.

START TRANSACTION; CREATE TABLE catalog_url_rewrite_product_category_temp 
SELECT DISTINCT * FROM catalog_url_rewrite_product_category; ALTER TABLE 
catalog_url_rewrite_product_category RENAME 
catalog_url_rewrite_product_category_backup; ALTER TABLE 
catalog_url_rewrite_product_category_temp RENAME 
catalog_url_rewrite_product_category; DROP TABLE 
catalog_url_rewrite_product_category_backup; COMMIT;

Github issue. (Above solution is from there) https://github.com/magento/magento2/issues/33770

Solution Explanation: We take all DISTINCT data from catalog_url_rewrite_product_category so no more duplicate url_rewrite_id rows and add it to a temp table.

We rename the table catalog_url_rewrite_product_category to a temp name We rename the temp table that we stored the DISTINCT data back to the name of the original table of catalog_url_rewrite_product_category.

Magento adds all the required constraints/relations/indexes etc to the new table via the declarations in db_schema.xml on bin/magento setup:upgrade process.

Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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