Laravel Artisan Migration Command: The migrate:refresh Command

December 7, 2016 —John Koster

The migrate:refresh command can be used to reset and run all outstanding migrations again. This command is a shortcut to calling two other Artisan commands. The following examples are equivalent:

1# Reset all the migrations.
2php artisan migrate:reset
3 
4# Run all outstanding migrations.
5php artisan migrate

The same using the migrate:refresh helper command:

1# Reset and run all migrations.
2php artisan migrate:refresh

The options that are available for use are similar to those of the migrate command. The following table lists and explains the various options that are available:

Option/Flag Description Default Value
--database=CONNECTION_NAME The name of the database connection to use. These can be found in the databases.connections configuration entry. Assumes the value of the of the DB_CONNECTION environment variable, or mysql if no value has been set.
--force Forces the migrations to run in a production environment. Default behavior is to not run migrations in a production environment.
--path=PATH The path to the migrations file. The default migrations directory is database/migrations/.
--seed Specifying this flag will cause the db:seed command to be executed after the migrations have run. The default behavior is to not run the db:seed command afterwards.
--seeder The class name of the seeder class that should be used. DatabaseSeeder

The following examples demonstrate how to supply the various options and flags:

1# Specify the database connection.
2php artisan migrate:refresh --database=mysql
3 
4# Force in a production environment.
5php artisan migrate:refresh --force
6 
7# Specify the path to the migrations.
8php artisan migrate:refresh --path=database/setup_migrations
9 
10# Indicate that the db:seed command should be ran
11# after the refresh command has finished.
12php artisan migrate:refresh --seed
13 
14# Specify which seeder to use.
15php artisan migrate:refresh --seeder=CustomDatabaseSeeder

The db:seed command will be executed after the migrate:refresh command if the --seed flag is present or if a value for the --seeder option has been supplied.

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.