2

Whenever I delete a website, magento returns the error: Invalid website id requested. I've to delete from db tables core_store and core_store_group the website id and then I can log again in the admin.

Is a Magento bug or I have some problem in my magento instance?

PS: I usually create websites programmatically by the script:

$rootCategory = Mage::getModel('catalog/category');
$rootCategory->setStoreId(0)
    ->setName('Demo')
    ->setPath(1)
    ->setDisplayMode('PRODUCTS')
    ->setIsActive(1)
    ->save();


$website = Mage::getModel('core/website');
$website->setCode('demo')
    ->setName('demo')
    ->save();

//#addStoreGroup
/** @var $storeGroup Mage_Core_Model_Store_Group */
$storeGroup = Mage::getModel('core/store_group');
$storeGroup->setWebsiteId($website->getId())
    ->setName('demo')
    ->setRootCategoryId($rootCategory->getId())
    ->save();

//#addStore
/** @var $store Mage_Core_Model_Store */
$store = Mage::getModel('core/store');
$store->setCode('demo_en')
    ->setWebsiteId($storeGroup->getWebsiteId())
    ->setGroupId($storeGroup->getId())
    ->setName('demo_en')
    ->setIsActive(1)
    ->save();
2
  • 1
    How are you deleting the website? Do the core_store and core_store_group tables have the foreign key set on website_id? Feb 14, 2015 at 12:23
  • you're right, there aren't foreign keys in the tables!
    – apedic
    Feb 15, 2015 at 11:41

6 Answers 6

4

Your database got somehow corrupted and you are missing the foreign keys on the core_store and core_store_group tables (and maybe other tables too), so when you deleted the website, the associated store groups and store views weren't also deleted.

You could try running the Magento database repair tool and investigate more from there.

3

If u got this error after deleting store you can try this solution :

  1. Select core_website and look for website_id attribute.
  2. Delete all lines in core_store and core_store_group tables has website_id attribute reference to core_website.website_id.

hope this help you.

1

I had exactly the problem @Marina Gociu says. Some of the indexes were not working because of that. Note that after fixing the database you have to flush the caches.

0

The exception is thrown here: app/code/core/Mage/Core/Model/App.php:950

if (empty($this->_websites[$id])) {
    $website = Mage::getModel('core/website');
    if (is_numeric($id)) {
        $website->load($id);
        if (!$website->hasWebsiteId()) {
            throw Mage::exception('Mage_Core', 'Invalid website id requested.');

And the code looks like as you deleted the website and therefore the loading fails. But this is only a guess.

1
  • If i try to import attributes of products i am getting the error like, "Invalid website id requested" how can i solve this issue?
    – zus
    Dec 13, 2017 at 12:54
0

I am working in Magento 1.9 ... I am in a development environment and today, I attempted to test out adding a second store, then delete it as soon as I created it. Seems this caused an issue because now I cannot log into admin without getting an "Invalid Website ID requested" error.

The front end still works great - no problems there. I can place an order, navigate pages, etc., but can't get into admin.

I logged into phpmyadmin and looked at core_stores... see image. Yellow highlight is the one I created, then deleted in admin.

Ideas? Any advice is appreciated.

Screenshot of Magento Site

0

If u got this error after deleting store you can try this solution :

Select core_website and look for website_id attribute. Delete all lines in core_store and core_store_group tables has website_id attribute reference to core_website.website_id.

Very helpful post.

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.