dibs_ab
dibs_ab

Reputation: 723

addColumn yii migration position

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

Upvotes: 38

Views: 27892

Answers (2)

gvanto
gvanto

Reputation: 2084

$this->addColumn('{{%user}}', 'username', 
            $this->string()->notNull()->unique()->after('id')
            );

Upvotes: 54

SuVeRa
SuVeRa

Reputation: 2904

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` ');

Upvotes: 45

Related Questions