Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Rollback one specific migration in Laravel

I want*
to rollback only :
Rolled back: 2015_05_15_195423_alter_table_web_directories

*I run*
php artisan migrate:rollback, 3 of my migration are rolling back.
Rolled back: 2015_05_15_195423_alter_table_web_directories
Rolled back: 2015_05_13_135240_create_web_directories_table
Rolled back: 2015_05_13_134411_create_contacts_table


*I delete

both of my web_directories and my contacts table unintentionally. I never want that to happen, and if I can rollback only that specific one, this disaster will never happen.
by

2 Answers

Bharatgxwzm
Every time you roll back you get the last batch of migration. use the command
php artisan migrate:rollback --step=1
pankajshivnani123
If you look in your migrations table, then you’ll see each migration has a batch number. So when you roll back, it rolls back each migration that was part of the last batch.

If you only want to roll back the very last migration, then just increment the batch number by one. Then next time you run the rollback command, it’ll only roll back that one migration as it’s in a “batch” of its own.

Alternatively, from Laravel 5.3 onwards, you can just run:

php artisan migrate:rollback --step=1

That will rollback the last migration, no matter what its batch number is.

Login / Signup to Answer the Question.