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.
Sadly, I never want that to happen, and if I can rollback only that specific one, this disaster will never happen.
I hope
someone can teach me how to prevent this from happening again.
Any recommendation will be much appreciated.
Migrate tables one by one.
Change the batch number of the migration you want to rollback to the highest.
Run migrate:rollback.
May not be the most comfortable way to deal with larger projects.
As stated in the Laravel manual, you may roll back specific number of migrations using the
--step
optionEvery time you rollback you get the last batch of migration. use the command
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.something like this