Randall Smith
Randall Smith

Reputation: 41

Yii 2.0 advanced error on yii migrate during setup

In following the steps listed here to set up the advanced application. I get the following error when using yii migrate.

Yii Migration Tool (based on Yii v2.0.2)
Exception 'yii\base\InvalidConfigException' with message 'Unknown component ID: db'
in /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/di/ServiceLocator.php:136
Stack trace:
#0 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/console/controllers/MigrateController.php(96): yii\
di\ServiceLocator->get('db')
#1 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/base/Controller.php(149): yii\console\controllers\M
igrateController->beforeAction(Object(yii\base\InlineAction))
#2 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/console/Controller.php(91): yii\base\Controller->ru
nAction('', Array)
#3 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/base/Module.php(455): yii\console\Controller->runAc
tion('', Array)
#4 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/console/Application.php(161): yii\base\Module->runA
ction('migrate', Array)
#5 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/console/Application.php(137): yii\console\Applicati
on->runAction('migrate', Array)
#6 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application-
>handleRequest(Object(yii\console\Request))
#7 /home/randall_l_smith_2_gmail_com/ngcOne/vendor/yiisoft/yii2/yii(41): yii\base\Application->run()
#8 {main}

This is my config file

<?php
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=127.0.0.1;port=3306;dbname=ngcOne',
            'username' => 'root',
            'password' => '############',
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
    ],
];

MySQL seems to be operating properly (Connected using remote navicat, and the web based phpmyadmin without issue). This is all set up on a LEMP stack.

Anyone have any insight as to how to deal with this error?

Upvotes: 2

Views: 2470

Answers (1)

Randall Smith
Randall Smith

Reputation: 41

In my case I used a click to deploy LEMP stack in the Google Cloud platform.

In following the instructions here it did not work entirely as written.

I would modify the order to make more sense.

Install Composer

curl -s http://getcomposer.org/installer | php

mv composer.phar /usr/local/bin/composer

Install the application template

composer global require "fxp/composer-asset-plugin:1.0.0-beta4"

composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

Create a DB using whatever method best suits the situation

Modify environments (dev or prod) to point to your DB (common, console, and frontend) -key takeaway here is don't forget console config.

Run php init in your application directory, selecting development or production as appropriate. Config files will be copied from specified environment.

Set document roots for your application as required /frontend/www and /backend/www

Upvotes: 2

Related Questions