
Magento 2.4.3 upgrade – fix Integrity constraint violation: 1062 Duplicate entry for key ‘PRIMARY’, query was: ALTER TABLE `catalog_url_rewrite_product_category` ADD CONSTRAINT PRIMARY KEY (`url_rewrite_id`) – error message on setup:upgrade
Hi there,
If you are trying to update your store the last Magento version (once this post was written 2.4.3 is latest), and you are getting the following error message:
1 |
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '***' for key 'PRIMARY', query was: ALTER TABLE `catalog_url_rewrite_product_category` ADD CONSTRAINT PRIMARY KEY (`url_rewrite_id`) |
Then this is because you are having duplicated url rewrites on your database. So, to solve this out, you will need to remove those useless and duplicated entries. To reach this out successfully, i suggest performing the following steps gettng logged into your database:
1 2 3 4 5 |
CREATE TABLE catalog_url_rewrite_product_category_nodup AS SELECT * FROM catalog_url_rewrite_product_category; truncate table catalog_url_rewrite_product_category_nodup; insert into catalog_url_rewrite_product_category_nodup (select distinct * from catalog_url_rewrite_product_category); truncate table catalog_url_rewrite_product_category; insert into catalog_url_rewrite_product_category (select * from catalog_url_rewrite_product_category_nodup); |
Hope this help.
Enjoy.