WiAim WiAim - 1 year ago 203
PHP Question

Can't install yii2 advanced template, migrate command

When installed yii2 advanced template collided with the "migrate" problem.
After db creating I tried run yii migrate but receive this exception:

'yii\base\InvalidCallException' with message 'Setting read-only property: yii\console\Application::db'

I don't know why it happens, because config are OK and I can work with db through shell or dBeaver. OS Linux Mint. Thanks for help.

Console command "/usr/bin/php /var/www/html/advanced/yii migrate".


return [
'bootstrap' => ['gii'],
'modules' => [
'gii' => 'yii\gii\Module',
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
'username' => 'root',
'password' => 'pw',
'charset' => 'utf8',

Answer Source

Be sure that you set properly console/config/main.php (or main-local.php)

in component section .. db entry

return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'components' => [
    'db' => [

        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=your_db_name',
        'username' => 'your_username',
        'password' => 'your_pwd',
        'charset' => 'utf8',

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download