我有两个带有这些配置文件的数据库
'db' => require(__DIR__ . '/db.php'),
'db2' => require(__DIR__ . '/db2.php'),
db.php 文件
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;port=**;dbname=**',
'username' => '**',
'password' => '**',
'charset' => 'utf8'];
db2.php 文件
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;port=**;dbname=**',
'username' => '**',
'password' => '**',
'charset' => 'utf8'];
当我想在迁移中使用 db2 数据库配置时出现错误
public function init()
{
$this->db = 'db2';
parent::init();
}
public function up()
{
$this->createTable('logs', [
'id' => $this->primaryKey()->unsigned(),
'type' => $this->string(8)->notNull(),
'data' => $this->string(255)->notNull(),
'created_at' => $this->integer()->notNull()->unsigned(),
]);
}
public function down()
{
$this->dropTable('logs');
}
错误:
异常“yii\base\InvalidConfigException”,消息“无法实例化组件或类“db2”。”
有人尝试对两个数据库使用迁移吗?