Migration move change column position

How can I chage column position in yii2 migration. I see just addcolumn method

I don’t think such an option exists.

In your original migration you can add a position to the addColumn by doing something like

$this->addColumn('YourTableName', 'YourNewColumnName', $this->integer() . " AFTER ColumnNameToPlaceNewColumnAfter");

Ok, this bothered me, so I played around and it can indeed be accomplished by doing something along the lines of

$this->alterColumn('YourTableName', 'YourColumnName', $this->integer() . " AFTER ColumnNameToPlaceYourColumnAfter");

You need to include the $this->integer() part of the expression to work, obviously change integer() to whatever the data type is for that column that you are moving.

It would be nice is there was a moveColumn method.

1 Like

Yes it would be nice=) Thanks for advice