yii迁移在yii2中不起作用

时间:2016-10-12 04:25:49

标签: yii migration

我创建了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>                      

请帮帮我

1 个答案:

答案 0 :(得分:1)

Yii2 migration

缺少控制台的数据库组件设置,将其添加到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列表中。