Question

I have this strange issue with magento 2.3.4.

although I have already this patch Magento official patch

which claims that it solve this I keep having this issue with duplicate urls in my database.

This happened after we insert new products with duplicating old ones. When we duplicate a product and then need to unassign one category we get error:

Could not save product "id" with position 0 to category id

and product can't saved.

If we go to same category and try to remove product from there we get:

Something went wrong. Please try again later

and error in exception:

[2020-03-06 14:26:52] report.CRITICAL: Could not save product "40003" with position 0 to category 1674 {"exception":"[object] (Magento\\Framework\\Exception\\CouldNotSaveException(code: 0): Could not save product \"40003\" with position 0 to category 1674 at /myfolder/public_html/vendor/magento/module-catalog/Model/CategoryLinkRepository.php:90, Magento\\UrlRewrite\\Model\\Exception\\UrlAlreadyExistsException(code: 0): URL key for specified store already exists. at /myfolder/public_html/vendor/magento/module-url-rewrite/Model/Storage/DbStorage.php:304, Magento\\Framework\\Exception\\AlreadyExistsException(code: 0): URL key for specified store already exists. at /myfolder/public_html/vendor/magento/module-url-rewrite/Model/Storage/DbStorage.php:337, Magento\\Framework\\DB\\Adapter\\DuplicateException(code: 1062): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'link.html/mylink.htm' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID', query was: INSERT  INTO `url_rewrite` (`redirect_type`,`is_autogenerated`,`metadata`,`description`,`entity_type`,`entity_id`,`request_path`,`target_path`,`store_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?) at /home/wpaper/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 'link.html/mylink.htm' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID', query was: INSERT  INTO `url_rewrite` (`redirect_type`,`is_autogenerated`,`metadata`,`description`,`entity_type`,`entity_id`,`request_path`,`target_path`,`store_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?, ?) at /home/wpaper/public_html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'link.html/mylink.htm' for key 'URL_REWRITE_REQUEST_PATH_STORE_ID' at /home/wpaper/public_html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)"}

If you check previous error you will see that the link is:

link.html/mylink.htm

we use html at the end. I don't know why this error say htm

What we tried:

1.We used modules even paid for regenerate url rewrite table

2.We made a script and resave all products in our catalog

Nothing helped. After a while we have this issue again

Any ideas?

Was it helpful?

Solution

For whom having the same issue with migrated Magento 1 stores.

In magento 1 there was an attribute in db:

url_path

This is migrated to magento 2 and probably it shouldn't.

So if you truncate this attribute in db directly the issue with duplicate is gone.

We found this after a lot of searching and with little luck.

This is the solution tested and working....Just take a backup your db before.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top