Magento: The store that was requested wasn’t found. Verify the store and try again.

This article provides the root cause and solution to the following error on Magento:

The store that was requested wasn’t found. Verify the store and try again.

Scenario

In my case, this error happened when I imported staging or production database to my local setup. I hadn’t imported the core_config_data table from the staging/production database.

Root Cause

This error happened because there were some entries in the core_config_data table on my local setup for the stores that were not present in the stores table.

Solution

To fix the issue, I removed the entries from the core_config_data table for the stores that are not present in the stores table.

Select/Check the problematic entries

SELECT * FROM core_config_data WHERE scope_id NOT IN (SELECT store_id FROM store);

Delete the problematic entries

DELETE FROM core_config_data WHERE scope_id NOT IN (SELECT store_id FROM store);

That should fix the issue.

Hope this helps. Thanks.