Magento – Error, “URL key for specified store already exists” When I’m Adding Products or Moving a Category

magento2producturl-key

I'm getting the error, "URL key for specified store already exists" when I try moving or adding products to a category in Magento 2 (Version 2.1). I have searched all over for a fix and even tried the fix here on Gihub but still I keep getting the error. The other problem even is that when I manually add or change a "URL Key" to make it work I still get the error.

Any help would be much appreciated.

Best Answer

We had a similar issue where we couldn't save categories and after much database searching and debugging I found the issue was when it updated the product url's for the category. We'd imported and deleted products previously but found out they still had entries in the url_rewrite table. So the request_path already existed.

To clear it out I had to run the query

delete from url_rewrite where entity_type='product' and entity_id NOT IN (Select entity_id from catalog_product_entity);

To check if you do have ghost records you can run

select count(*) from url_rewrite where entity_type='product' and entity_id NOT IN (Select entity_id from catalog_product_entity);

Good luck

Related Topic