Magento – Magento2 : URL key for specified store already exists while updating the existing product

admincategorymagento2

I am using the magento version 2.0.9 version for my site.

I am getting this Url key for specified store is already exist while updating the product or assigning the product for custom option and click on Save button.

I have deleted all entries in URL rewrite table in the database also. But I am still getting this error while updating any product.

Any idea for this error?

Best Answer

I came here searching for a similar issue but with Category save. So when I tried to save the category it threw same error "URL key for specified store already exists.".

After debugging by removing the try..catch block at insertMultiple() method of Magento\UrlRewrite\Model\Storage\DbStorage. I identified that while saving the category Magento was trying to re-build url rewrites for assigned products also. And few products had same url_key and that was throwing duplicate records error. As url_rewrite table has a UNIQUE contraint on request_path, store_id columns.

See exception.log to find out the url_key that is creating issue.

So I just made the url_key unique for products and that resolved the issue.

Hope these debugging steps may prove helpful to somebody who stumbles here again.

Related Topic