yii\db\Migration db property

I has set Yii::$app->db and Yii::$app->db2;

I add this code to the migration class

public $db = ‘db2’;

command yii migrate still apply the migration to default database connection which is db, not db2

then i add this to the migration class

protected function getDb()
{
return Yii::$app->db2;
}

still command yii migrate apply to db, not db2

so i need to do command yii migrate --db=db2 to make it work.

I want to just use command yii migrate and db selection determine by the migration class.

Hi.

[…] command yii migrate still apply the migration to default database

This behaviour, with the solution ready to apply is described in the API.
Have a look:

My bad, i should has check the doc properly instead of just rely on chat gpt.

Thanks for helping.

Wait, what…I am sorry, I felt a little cringe with the chatGPT thing, but I guess it’s the new way now. :man_facepalming:

lol, i know the limitation of chat gpt, has been correcting that AI many time, but this time i just so lazy to double check in the yii2 doc or could also say feel too comfortable with chatgpt when it give correct solution many time before that, so it happen, a blunder on my part.

1 Like