phpmagentocomposer-phpmagento2magento-2.0

Magento 2 - 'Area code not set:' after adding sample data


So i've gotten magento 2 working all running fine, I've even started on my own theme, but i've tried to install the sample data after I've installed magento. And it has returned 'Area code not set:' in terminal, below is a little run through of my steps.

bin/magento sampledata:deploy    
composer update

Which returns:

Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing magento/module-catalog-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-bundle-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-widget-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-customer-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/sample-data-media (100.0.3)
    Downloading: 100%         

  - Installing magento/module-theme-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-cms-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-catalog-rule-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-sales-rule-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-review-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-tax-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-grouped-product-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-downloadable-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-msrp-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-sales-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-product-links-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-configurable-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-wishlist-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-swatches-sample-data (100.0.3)
    Downloading: 100%         

  - Installing magento/module-offline-shipping-sample-data (100.0.3)
    Downloading: 100%         

Writing lock file
Generating autoload files

I've then run:

bin/magento setup:upgrade

And i get the following error shown in a screen shot below, i can't seem to find anyone else having the same error online.

terminal window of Area code not set:

  [Magento\Framework\Exception\SessionException]                       
  Area code not set: Area code must be set before starting a session.  

  [Magento\Framework\Exception\LocalizedException]  
  Area code is not set    

And now my mage install just isn't working - error returns:

Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory.

Which I can't do because it returns and error, any help would be awesome.


Solution

  • Had the same issue and was able to resolve it.

    Try running this command first:

    php bin/magento sampledata:reset
    

    And then re-run:

    php bin/magento setup:upgrade
    

    In case you had a memory exhausted error (which I encountered), try adding -dmemory_limit=6G on your setup:upgrade command.

    php -dmemory_limit=6G bin/magento setup:upgrade