I want to add a column at the seventh place in the table, I am using
$this->addColumn('table_name','column_name','type');
adds the column at the end. Is there any way where I can mention the place to add column? Or any after column keyword to add my new column after, for exapmle, password column. I have learnt aboout migration from Yii Doc
Yii provides the database migration feature that allows you to keep track of database changes. Yii provides the following migration command line tools − Create new migrations. Revert migrations. Apply migrations.
To run specific migration, you can mark(skip) migrations upto just before one you want run. You can mark migration by using one of following command: Using timestamp to specify the migration yii migrate/mark 150101_185401. Using a string that can be parsed by strtotime() yii migrate/mark "2015-01-01 18:54:01"
This should work!
$this->addColumn('table_name', 'column_name', 'type AFTER column6');
examples:
$this->addColumn('tbl_posts', 'email', 'VARCHAR(150) AFTER `name` ');
$this->addColumn('tbl_posts', 'phone', 'string AFTER `email` ');
$this->addColumn('{{%user}}', 'username',
$this->string()->notNull()->unique()->after('id')
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With