我尝试执行控制台迁移到不同的connecton,但关闭失败
在我的连接中我有
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=pos_db',
....other configs
],
'connection_identifier' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=newdbo',
...other configs
],在我的控制台中我有
public function init()
{
$this->db = 'connection_identifier';
parent::init();
}
public function safeUp()
{
$this->createTable('database_connection_domains', [
'id' => $this->primaryKey(),
'domain'=>$this->text()->notNull(),
'connection_id'=>$this->integer()->notNull(),
'created_at' => $this->integer()->notNull(),
'status'=>$this->integer()->defaultValue(0),
'FOREIGN KEY (connection_id) REFERENCES database_connections (id) ON DELETE RESTRICT ON UPDATE CASCADE',
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('database_connection_domains');
}当我运行up迁移时,在newdbo数据库上正确创建了数据库。问题出现在down命令中,其中表没有被删除。我如何让它丢弃这个表。
当我运行/yii migrate/fresh时,我得到了一个错误的Base table or view already exists: 1050 Table 'database_connections' already exists,这意味着表没有被删除,我错过了什么?
发布于 2019-02-18 22:03:18
./yii migrate/fresh不使用迁移来清理数据库,而是使用custom implementation,它只按正确的顺序删除所有表。因此您数据库组件的设置永远不会被使用。您需要在命令调用时配置数据库:
./yii migrate/fresh --db=connection_identifierhttps://stackoverflow.com/questions/54748066
复制相似问题