我创建了yii2项目。当我键入yii migrate commant时,它显示以下错误:
消息'类db不存在'的异常'ReflectionException'
in C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
i\Container.php:422
Stack trace:
#0 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
i\Container.php(422): ReflectionClass->__construct('db')
#1 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
i\Container.php(362): yii\di\Container->getDependencies('db')
#2 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
i\Container.php(154): yii\di\Container->build('db', Array, Array)
#3 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
i\Instance.php(157): yii\di\Container->get('db')
#4 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
i\Instance.php(131): yii\di\Instance->get(NULL)
#5 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
onsole\controllers\MigrateController.php(152): yii\di\Instance::ensure('db',
yii\\db\\Connecti...')
#6 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
ase\Controller.php(152): yii\console\controllers\MigrateController->beforeAc
on(Object(yii\base\InlineAction))
#7 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
onsole\Controller.php(119): yii\base\Controller->runAction('', Array)
#8 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
ase\Module.php(454): yii\console\Controller->runAction('', Array)
#9 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii2
onsole\Application.php(180): yii\base\Module->runAction('migrate', Array)
#10 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii
console\Application.php(147): yii\console\Application->runAction('migrate',
ray)
#11 C:\OpenServer\domains\chamber_development\yii2chamber\vendor\yiisoft\yii
base\Application.php(375): yii\console\Application->handleRequest(Object(yii
onsole\Request))
#12 C:\OpenServer\domains\chamber_development\yii2chamber\yii(27): yii\base\
plication->run()
#13 {main}
c:\OpenServer\domains\chamber_development\yii2chamber>
请帮帮我
答案 0 :(得分:1)
缺少控制台的数据库组件设置,将其添加到console / config / main-local.php文件以进行本地开发:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
],
],
对于生产服务器,根据数据库设置更正此文件。
请注意-local
个文件位于.gitignore
列表中。