Rolling Back the Last Database Migration

Problem

You want to "undo" your last database migration.

Solution

Use the php artisan migrate:rollback command.

$ php artisan migrate:rollback

The command will list the migrations which have been undone.

To see what rollback will do, use the --pretend option.

$ php artisan migrate:rollback --pretend

You can also specify a database connection other than the default one.

$ php artisan migrate:rollback --pretend --database=other-one

Discussion

This command will undo the last "set" of migrations.

If the previous time you ran php artisan migrate ended up performing three different migrations, then php artisan migrate:rollback will undo those three migrations.

This encourages small, incremental changes to your database.

comments powered by Disqus