Yii2: Cannot perform RBAC migration (You should configure "authManager"...)

robsch picture robsch · May 27, 2015 · Viewed 13.2k times · Source

As it is described here I'm trying to do the migration in order to let yii create the user authentication tables. However I get the error:

Exception 'yii\base\InvalidConfigException' with message 'You should configure "authManager" component to use database before executing this migration.'

The authManager is present in the configuration but I still get that error. Configuration:

'components' => [
    ...
    'db' => $db,
    'authManager'  => [
        'class'        => 'yii\rbac\DbManager',
        //            'defaultRoles' => ['guest'],
    ],
    ...
],

What's the problem?

Answer

robsch picture robsch · May 27, 2015

Problem was quite simple: The configuration was not used. yii migrate is a console command and usually the configuration for such commands is placed in a seperated file.

In case of yii2-app-base template, from which I have created my application, there is a config/console.php configuration file where the authManager needs to be declared. It is not sufficient to have it in the config/web.php declared only.

In case of yii2-app-advanced the authManager should be declared in console/config/main.php and not in the backend or frontend configuration files.