laravel migration re-organising column order

user391986 picture user391986 · Dec 3, 2013 · Viewed 22.9k times · Source

When you create a new column in a table you can use the ->after('column name') to dictate where it goes. How can I create a migration that re-orders the columns in the right order I want?

Answer

Odin Thunder picture Odin Thunder · Mar 3, 2017

Try this, hope it help you to find right solution:

public function up()
{

    DB::statement("ALTER TABLE example MODIFY COLUMN foo DATE AFTER bar");

}

public function down()
{

    DB::statement("ALTER TABLE example MODIFY COLUMN foo DATE AFTER bar");

}