Laravel Artisan Migration Command: The migrate:rollback Command

December 7, 2016 —John Koster

The migrate:rollback command is used to undo the last database migration. There are a number of options and flags that are available to use when calling the migrate:rollback command. The following table lists and describes the various options.

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.
--pretend Does not run any migrations and instead displays the SQL queries that would be run. The default behavior is to run the migrations.

The following examples demonstrate how to use the migrate:rollback command:

1# Call the command with defaults.
2php artisan migrate:rollback
3 
4# Call the command while specifying the connection name.
5php artisan migrate:rollback --database=mysql
6 
7# Rollback the migrations on a production environment.
8php artisan migrate:rollback --force
9 
10# Do not perform any database connections and simply list
11# the SQL queries that would have been performed.
12php artisan migrate:rollback --pretend

The migrate:rollback will undo the migrations with the highest batch number. If multiple migrations have the same highest batch number they will all be removed.

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.