When we upgrade magento version then sometimes we faced below error while setup upgrade command run.
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘227569538’ for key ‘catalog_url_rewrite_product_category.PRIMARY’, query was: ALTER TABLE `catalog_url_rewrite_product_category` ADD CONSTRAINT PRIMARY KEY (`url_rewrite_id`), DEFAULT CHARSET=’utf8′, DEFAULT COLLATE=’utf8_general_ci’
We can fix above error by delete all duplicate records:
Here is query for delete duplicate records.
DELETE t1.* FROM catalog_url_rewrite_product_category t1 INNER JOIN (SELECT url_rewrite_id FROM catalog_url_rewrite_product_category GROUP BY url_rewrite_id HAVING COUNT(*)>1) t2 ON t1.url_rewrite_id = t2.url_rewrite_id
I hope this blog is useful to solve Duplicate entry for table ‘catalog_url_rewrite_product_category. In case, I missed anything or need to add some more information, Don’t heisted to leave a comment in this blog, I’ll get back with some positive approach.
Keep loving ❤️ Keep inspiring 🤩 Keep liking 👍 No sharing 😂