Can't create the page in the Store View programmatically.

I have two stores:

  1. English
  2. French

    $pageModel = \Magento\Framework\App\ObjectManager::getInstance()


$origialStoreId = 1;

$storeId = 2;

Could not save the page: URL key for specified store already exists.

1 Answer 1


This is because URL rewrite rule - url_rewrite table:

UNIQUE KEY `URL_REWRITE_REQUEST_PATH_STORE_ID` (`request_path`,`store_id`),

Make two test cases:

1) Create a CMS page: Page in Websites > All Store Views

Take a look at url_rewrite. A record will be generated for each store.

enter image description here

So, in this case, your code above will have an error. Because Magento will try to insert the same row to database.

2) Create a CMS page: Page in Websites > Choose a specific store

Now we can use your code above.

Should take a look module cms and url-rewrite for more details.


-Should use $pageModel->setStores($storesArray) to set stores for the cms page.

For example:

  • I've used setStore method ))
    – RDK
    Commented Dec 13, 2017 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.