Laravel Migrate Fresh Command

Laravel Migrate Fresh Command

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:

$ php artisan migrate:refresh

Rolling back: 2014_10_12_100000_create_password_resets_table
Rolled back:  2014_10_12_100000_create_password_resets_table
Rolling back: 2014_10_12_000000_create_users_table
Rolled back:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table

Now, with the new fresh command:

$ php artisan migrate:fresh

Dropped all tables successfully.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  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: Laravel 5.5 / Migrations


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Software Engineer Lead (PHP)
Remote
CivicPlus, LLC
Full-time Senior Web Developer
Detroit, MI
Wayne State University
Senior Software Engineer
Sydney, Australia
FoodByUs
Full Stack Engineer
Remote or Medford, Oregon
Empire Medical
Laravel Developer (fulltime - Dutch only)
Netherlands
Qbixx | Webservices
Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Senior Quality Assurance Engineer
Remote
Bisnow Media