Migration move change column position


(Spektr08) #1

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


(DBCreator) #2

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");

(DBCreator) #3

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.


(Spektr08) #4

Yes it would be nice=) Thanks for advice