cancel
Showing results for 
Search instead for 
Did you mean: 

Area code not set: Area code must be set before starting a session

Area code not set: Area code must be set before starting a session

I am running 2.0.7 CE and i am trying to upgrade to 2.1.0 CE and i get this error 

An error occurred while executing job "setup:upgrade {"command":"setup:upgrade"}": Could not complete setup:upgrade {"command":"setup:upgrade"} successfully: Area code not set: Area code must be set before starting a session.

 

no idea where to start on this one

 

Thanks in advance

7 REPLIES 7

Re: Area code not set: Area code must be set before starting a session

Hi @daschenbrener

 

You may try solution listed on following link Magento 2: Fixing Area code Not Set Exceptions.

 

How did you install your existing Magento 2 setup? Did you use composer? (http://devdocs.magento.com/guides/v2.1/release-notes/tech_bull_21-upgrade.html#tb-upgr-nosamp)

 

Do you have sample data installed on your existing Magento 2 setup?

---
Problem Solved Click Accept as Solution!:Magento Community India Forum

Re: Area code not set: Area code must be set before starting a session

The install was a bitnami setup, no sample data installed.

 

And yes I tried that patch also with no different result

 

and please forgive my ignorance, where would i go to apply that fix , or to try it to see if it will fix.

 

public function __construct(
    \Magento\Framework\App\State $appState,
    $name=null
)
{
    $appState->setAreaCode('frontend');
    parent::__construct($name);
}

 

Thanks in advance 

Re: Area code not set: Area code must be set before starting a session

Hi @daschenbrener

 

You may try following commands on Magento root directory.

 

php bin/magento sampledata:reset

 

 

And then re-run:

php bin/magento setup:upgrade

Please see following post http://stackoverflow.com/a/35330389 , it may help.

 

---
Problem Solved Click Accept as Solution!:Magento Community India Forum

Re: Area code not set: Area code must be set before starting a session

Just got this same error upgrading from CE2.1.1 to CE2.1.2

No sample data. Have own data migrated.

 

Patch mentioned above did not help.

Re: Area code not set: Area code must be set before starting a session

Hello,

 

I have same error using version 2.1 with a custom CLI

Patch mentioned above did not help.

 

Do somebody has an answer ?

 

Thank you.

 

Anthony

Re: Area code not set: Area code must be set before starting a session

In the model/helper that you execute in your custom CLI require it in __construct() and save to class property:

protected $_appState;

public function __construct(\Magento\Framework\App\State $appState ) {
$this->_appState = $appState;
}

and then in the main execution method of this model (not directly in the __construct()) you set the area code with:

 

$this->_appState->setAreaCode('adminhtml');

 

Re: Area code not set: Area code must be set before starting a session

Thank you!