cancel
Showing results for 
Search instead for 
Did you mean: 

"URL key for specified store already exists." cannot save category Magento 2.1.4

"URL key for specified store already exists." cannot save category Magento 2.1.4

I am facing "URL key for specified store already exists" error when i am trying to update existing category name as its appearing in some categories.

I am using Magento 2.1.4.
I have read so many articles where it stated that it is solved in magento 2.1 version but its appearing again. Let me know

FYI I'm using multi-store
Please help me to resolve the issue.

Thanks

10 REPLIES 10

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

We had this problem for a while and read many articles nothing worked. One dirty fix is I hope you migrated your store then just delete that categories that causing problem and recreate it again also add products in category. The issues is there url's and entity id's in database. When adding products you also need to take those products out from the category. This should help you. If you don't mind about time just do it.


Things need to do:
Delete the categories.
Recreate it, when adding products to category, some products have duplicated url so you need to delete them(means you need to add products manually like 10 everytime if you get problem in 10 just add one by one delete the duplicate url).

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

Hello

 

This is happening on Magento 2.1.7. I have installed this trough XAMPP and I don't consider these to be good solutions at all as they might affect Magento data in the future.

 

How come this is not fixed. What can we do?

 

This is happening to me with a Default Category and 2 Sub categories (Subcategory 1 and Subcategory 2) and only 2 products (Product 1 and Product 2) which I want to add to Subcategory 1 and Subcategory 2 respectively.

 

Of course all URL keys are unique. What's going on? Shouldn't Magento team fix this?

 

Thanks

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

@aasim110 @alb2001

 

I did following changes and it is working.

 

Magento\UrlRewrite\Model\Storage\DbStorage.php file

 

protected function insertMultiple($data)
    {
        try {
			$keys=array();
			foreach($data as $current=>$_data)
			{
				$key = $_data['request_path'];
				if(in_array($key,$keys))
				{
					unset($data[$current]);
				}else
				{
					$keys[]=$key;
				}
			}
			
            $this->connection->insertMultiple($this->resource->getTableName(self::TABLE_NAME), $data);
        } catch (\Exception $e) {
            if ($e->getCode() === self::ERROR_CODE_DUPLICATE_ENTRY
                && preg_match('#SQLSTATE\[23000\]: [^:]+: 1062[^\d]#', $e->getMessage())
            ) {
                throw new \Magento\Framework\Exception\AlreadyExistsException(
                    __('URL key for specified store already exists.')
                );
            }
            throw $e;
        }
    }

Hope it will help you.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

Hello

 

I appreciate your help as I saw many people proposing different solutions and one of them was this. However is this an approved solution? Will it cause trouble in the future? I mean, this is even happening with 2 categories and 2 products only!!!

Is there an explanation of this happens? As it seems not everyone has this issue..

 

Thanks

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

@alb2001

 

i did that code and it is working fine for me.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

Hi

I am not indicating it doesn't work. i am just asking if it's a recommended solution at all. Changing core code could cause problems in the future. That's why I ask. So I wonder if there's a proposed solution by Magento, or if they are even aware of it.

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

@alb2001

 

Magento team still not provide solution for that, meantime you can use this solution. whenever they provide update then readme file and remove this code.

 

Hope you can understand.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

Thank you Sunil

Re: "URL key for specified store already exists." cannot save category Magento 2.1.4

@Sunil Patel this solution does't working for me, As I'm using multi-website with 5 website and more then 30K products.