9

I had two websites with different store and storeviews. I just deleted one website which is not the default one. After deleting it the admin panel page and also the front page shows this error

exception 'Magento\Framework\Exception\NoSuchEntityException' with message 'Requested store is not found' in C:\wamp\www\magento\vendor\magento\module-store\Model\StoreRepository.php:111 Stack trace: #0 

C:\wamp\www\magento\vendor\magento\module-store\Model\StoreManager.php(164): Magento\Store\Model\StoreRepository->getById('2') #1 C:\wamp\www\magento\var\generation\Magento\Store\Model\StoreManagerInterface\Proxy.php(119): Magento\Store\Model\StoreManager->getStore('2') #2 C:\wamp\www\magento\vendor\magento\module-store\Model\Resolver\Store.php(29): Magento\Store\Model\StoreManagerInterface\Proxy->getStore('2') #3 C:\wamp\www\magento\vendor\magento\framework\App\Config\ScopeCodeResolver.php(49): Magento\Store\Model\Resolver\Store->getScope('2') #4 C:\wamp\www\magento\vendor\magento\module-config\App\Config\Source\RuntimeConfigSource.php(82): Magento\Framework\App\Config\ScopeCodeResolver->resolve('stores', '2') #5 C:\wamp\www\magento\vendor\magento\module-config\App\Config\Source\RuntimeConfigSource.php(58): Magento\Config\App\Config\Source\RuntimeConfigSource->loadConfig() #6 C:\wamp\www\magento\vendor\magento\framework\App\Config\ConfigSourceAggregated.php(40): Magento\Config\App\Config\Source\RuntimeConfigSource->get('') #7 C:\wamp\www\magento\var\generation\Magento\Framework\App\Config\ConfigSourceAggregated\Proxy.php(95): Magento\Framework\App\Config\ConfigSourceAggregated->get('') #8 C:\wamp\www\magento\vendor\magento\module-config\App\Config\Type\System.php(98): Magento\Framework\App\Config\ConfigSourceAggregated\Proxy->get() #9 C:\wamp\www\magento\vendor\magento\framework\App\Config.php(139): Magento\Config\App\Config\Type\System->get('default/web/sec...') #10 C:\wamp\www\magento\vendor\magento\framework\App\Config.php(90): Magento\Framework\App\Config->get('system', 'default/web/sec...') #11 C:\wamp\www\magento\vendor\magento\framework\App\Config.php(103): Magento\Framework\App\Config->getValue('web/secure/use_...', 'default', NULL) #12 C:\wamp\www\magento\vendor\magento\module-store\Model\HeaderProvider\Hsts.php(48): Magento\Framework\App\Config->isSetFlag('web/secure/use_...') #13 C:\wamp\www\magento\vendor\magento\framework\App\Response\HeaderManager.php(41): Magento\Store\Model\HeaderProvider\Hsts->canApply() #14 C:\wamp\www\magento\vendor\magento\framework\Interception\Interceptor.php(123): Magento\Framework\App\Response\HeaderManager->beforeSendResponse(Object(Magento\Framework\App\Response\Http\Interceptor)) #15 C:\wamp\www\magento\var\generation\Magento\Framework\App\Response\Http\Interceptor.php(117): Magento\Framework\App\Response\Http\Interceptor->___callPlugins('sendResponse', Array, Array) #16 C:\wamp\www\magento\vendor\magento\framework\App\Http.php(185): Magento\Framework\App\Response\Http\Interceptor->sendResponse() #17 C:\wamp\www\magento\vendor\magento\framework\App\Http.php(156): Magento\Framework\App\Http->handleDeveloperMode(Object(Magento\Framework\App\Bootstrap), Object(Magento\Framework\Exception\NoSuchEntityException)) #18 C:\wamp\www\magento\vendor\magento\framework\App\Bootstrap.php(263): Magento\Framework\App\Http->catchException(Object(Magento\Framework\App\Bootstrap), Object(Magento\Framework\Exception\NoSuchEntityException)) #19 C:\wamp\www\magento\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http)) #20 {main}

What should I do now? I tried

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento indexer:reindex

from command prompt. But it shows the same error in command prompt also. The cmd error is :

C:\wamp\bin\php\php5.6.30>php C:\wamp\www\magento\bin\magento indexer:reindex
Xdebug requires Zend Engine API version 220121212.
The Zend Engine API version 220131226 which is installed, is newer.
Contact Derick Rethans at http://xdebug.org/docs/faq#api for a later version of Xdebug.




  [Magento\Framework\Exception\NoSuchEntityException]
  Requested store is not found



indexer:reindex [index1] ... [indexN]
3
  • Remove var folder and check it again. Commented Jan 24, 2017 at 10:33
  • share the error which command promt show to you. Commented Jan 25, 2017 at 3:04
  • @DhirenVasoya : Added the error in question
    – Zammuuz
    Commented Jan 25, 2017 at 4:22

11 Answers 11

20

You need to run the following query in your database, and then try to open the website.

SET FOREIGN_KEY_CHECKS=0;
UPDATE `store` SET store_id = 0 WHERE code='admin';
UPDATE `store_group` SET group_id = 0 WHERE name='Default';
UPDATE `store_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;
8
  • 2
    No this didn't solved the issue. :(
    – Zammuuz
    Commented Jan 25, 2017 at 2:17
  • This is the only thing that worked for me!
    – Wildcard27
    Commented Apr 29, 2017 at 2:18
  • 1
    Thank you very much Dhiren Vasoya, it worked for me to. Tested on Magento 2.2 Commented Jan 24, 2018 at 13:09
  • @Dhiren Vasoya what this command actually do ?
    – ephemeral
    Commented Feb 8, 2018 at 12:09
  • Some times dua to some reason, default store_id may be changes, So above command set it default again, and magento working fine. Commented Feb 8, 2018 at 14:09
22

I just recently came across this same situation after migrating from Magento 1.6.1.0 to 2.1.4 and hope my answer can be of assistance. The problem came from deleting multiple stores 96 of them to be exact. I tried all the other answers here but was still getting the same error.

The fix for me was removing the old store data from inside of the "core_config_data". The problem is that when the Magento is loading the run time configuration data it is finding the old stores and trying to resolve them. Before cleaning the data from the database I HIGHLY recommend you run the SELECT query below to make sure you delete the correct stores.

SELECT * FROM core_config_data WHERE scope = 'stores';

WARNING: MAKE SURE TO BACKUP YOUR DATABASE BEFORE RUNNING THIS!

DELETE FROM core_config_data WHERE scope_id != 1 AND scope = 'stores';
1
9

This generally happens whenever config.php and the database get out of sync. For example, whenever I import a database back to my local development environment.

Here were the steps I used to troubleshoot and fix this.

  1. Make the error messages more helpful:

Change vendor/magento/module-store/Model/StoreRepository.php to this (on your local, temporarily)

// Around line 74
        if ($store->getId() === null) {
        
// Add this to see a backtrace
            // debug_print_backtrace();            

// Add this to see the store code causing the issue: (code:{$code})
            throw new NoSuchEntityException(
                __("The store (code:{$code}) that was requested wasn't found. Verify the store and try again.")
            );
        }
        
// .......
// Around line 114, same kind of thing...

        if ($store->getId() === null) {

            // debug_print_backtrace();

            throw new NoSuchEntityException(
                __("The store ID ({$id}) that was requested wasn't found. Verify the store and try again.")
            );
        }        

Run php bin/magento s:up and make a note of the store id and/or store codes that are causing the issues. If you have added the backtrace, that will spool variables forever and you might need to do something like this instead: php bin/magento s:up > output.txt (wait 3 minutes, press ctrl-d to kill it) less output.txt

  1. Go through app/etc/config.php and make sure all the stores line up with whatever is in the store table in the database. Note the store id from step 1, that will give you clues where to look. If there are differences, change config.php and not the database.

  2. Run this against the database:

## Change scope_id value (99) to whatever store_id you got in step #1
DELETE FROM `core_config_data` WHERE scope_id = 99

## Change like value ('%xx_en%') to whatever store code you got in step #1
DELETE from flag where flag_data like '%xx_en%'
  1. Run php bin/magento s:up again, hopefully there are no errors this time. Otherwise you may have to repeat some steps.
3
  • Worked for me, thank you! Commented Dec 1, 2021 at 6:28
  • @Silas Palmer Thanks it's help full for debug track and easily found issues. Commented Mar 24, 2022 at 10:28
  • Thanks for very good explanation, you took my debug skills to another level! Commented Oct 7, 2022 at 21:58
3

In this case, I have to restore that tables store, store_group, store_website. As it was before the migration Magento 2

enter image description here

1

If the above doesn't fix the issue and it relates to CMS pages, you can look at the database table cms_page_store and see what the store id that is missing by using the following query:

select * from cms_page_store where store_id > put your current max store id here

You can fix this by assigning a current store id to those pages:

update cms_page_store set store_id = 2 where store_id = store id that doesn't exist
0

The error occurred for me during a reindex of Catalog Search while using the Elasticsearch engine. Magento 2.0.0 Commerce (and possibly other versions) have a bug resolved by the following patch.

diff --git a/vendor/magento/module-elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php b/vendor/magento/module-elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php
index aa89657..f5e8a23 100644
--- a/vendor/magento/module-elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php
+++ b/vendor/magento/module-elasticsearch/Model/Adapter/BatchDataMapper/PriceFieldsProvider.php
@@ -50,9 +50,8 @@ class PriceFieldsProvider implements AdditionalFieldsProviderInterface
      */
     public function getFields(array $productIds, $storeId)
     {
-        $websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
         $priceData = $this->dataProvider->getSearchableAttribute('price')
-            ? $this->resourceIndex->getPriceIndexData($productIds, $websiteId)
+            ? $this->resourceIndex->getPriceIndexData($productIds, $storeId)
             : [];

         $fields = [];
0

Confirm your store id and delete all the records of store which doesn't exist 'cms_page_store' & 'cms_block_store'...

0

in my case , magento 1.9 upgrade to magento 2.3

I re-added the store item.

I re-added the store item.

0

I just experienced this after importing the database from a different environment (Magento Commerce Cloud). Before I did anything, I updated the base_urls as needed, but when I tried to navigate to the site, it threw this error and wouldn't load. I simply flushed cache to resolve. I'm sure there are many different reasons for the error to occur, so I wanted to mention this solution in case anyone else finds themselves in a similar scenario.

Of course, to clear the cache, run:

$ php bin/magento cache:flush

0

enter image description here

If is above question, we can see the storeRepositor getStore() method, it has a param with number, and it is a missing store id, and you can run sql below:

select * from core_config_data where scope_id={@store_id};

delete all missing store config from above sql:

delete * from core_config_data where scope_id={@store_id};

refresh page, everything is working well general;

Supplement:

When magneto is on configuration progress, it will insert data step by step, so if one module's sequence is wrong order, some config data will insert to database before store create, then above issue will appear.

-4

It's a bug in Magento 2 already fixed in develop.

All query results to tables store, store_group, store_websites are being cached. The problem occurs because cache isn't cleaned properly after store, store group or website is added/deleted.

To get a fix see changes in app/code/Magento/Store/etc/di.xml and app/code/Magento/Store/Model/StoreManager.php.

It must resolve the issue.

1
  • What does "To get a fix see changes in..." mean? Commented Dec 15, 2017 at 9:26

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