Posts Learn Components new Snippets new Categories Tags About
/

How to Order Migrations in Laravel

Learn how to change the order of your migrations in Laravel to get the table migrated on the preferred order

Created on Jul 05, 2021

25 views

To change the order of migrations, you can simply rename the migration file "timestamps" value.

Imagine having the "users" table with a timestamp "2014_10_12_000000".
2014_10_12_000000_create_users_table.php

Now you can change "2014_10_12_000000" to "2014_10_14_000000" to change the order.
2014_10_14_000000_create_users_table.php

Full Steps
  1. Rollback existing migration "php artisan migrate:rollback"
  2. Change the timestamps of the migration
  3. Run migration again "php artisan migrate"

The migration will be executed in ascending order of the timestamps.
new

If you like our tutorial, do make sure to support us with some coffee. We need the juice to write the content during the night 🤙🏻