I learned that add_column
has an :after
option to set where the column gets inserted. Too bad I learned about it :after adding a bunch.
How can I write a migration to simply reorder columns?
I learned that add_column
has an :after
option to set where the column gets inserted. Too bad I learned about it :after adding a bunch.
How can I write a migration to simply reorder columns?
Stefan's solution is perfect if you're dealing with just a handful of columns. If you have multiple columns to be re-arranged AND happen to be on a Mac, I suggest you take a look at Sequel Pro, a nifty database management tool that makes re-ordering database columns a breeze. Just drag and drop.
PS: I am not affiliated with them in any way.
You can call
change_column
, but you have to repeat the column type (just copy and paste it from your other migration):Or if you have to reorder multiple columns in one table:
change_column
callsALTER TABLE
under the hood. From the MySQL documentation: