Laravel Migrate Fresh Command

Tutorials

April 7th, 2017

migrate-fresh.png

You may be familiar with the migrate:refresh command that allows you to rollback and re-runs all of your migrations. This helps when you need to rebuild your database during development.

Coming to Laravel 5.5 is an improvement on this with a new command named migrate:fresh. The difference between “refresh” and “fresh” is that the new fresh command skips all the down methods or the rollback by dropping the tables, then running through the up methods.

Here is the command output showing the differences:

1$ php artisan migrate:refresh
2
3Rolling back: 2014_10_12_100000_create_password_resets_table
4Rolled back: 2014_10_12_100000_create_password_resets_table
5Rolling back: 2014_10_12_000000_create_users_table
6Rolled back: 2014_10_12_000000_create_users_table
7Migrating: 2014_10_12_000000_create_users_table
8Migrated: 2014_10_12_000000_create_users_table
9Migrating: 2014_10_12_100000_create_password_resets_table
10Migrated: 2014_10_12_100000_create_password_resets_table

Now, with the new fresh command:

1$ php artisan migrate:fresh
2
3Dropped all tables successfully.
4Migration table created successfully.
5Migrating: 2014_10_12_000000_create_users_table
6Migrated: 2014_10_12_000000_create_users_table
7Migrating: 2014_10_12_100000_create_password_resets_table
8Migrated: 2014_10_12_100000_create_password_resets_table

What is also beneficial with this new command is it pairs well with the recent 5.4.17 release because it made the up and down methods in migrations optional. Now you can leave off the down and still quickly reset your local database.

The new migrate:fresh will be included in Laravel 5.5 that is scheduled to be released in July or August of this year. For more information on this new feature, you can also check out Taylor’s announcement post.

Update: If you’d like to utilize on your current Laravel app check out this package by Spatie.

Filed in:

Eric L. Barnes

Eric is the creator of Laravel News and has been covering Laravel since 2012.