Rollback one specific migration in Laravel

2019-01-10 05:30发布

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.

11条回答
孤傲高冷的网名
2楼-- · 2019-01-10 05:54

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.

查看更多
地球回转人心会变
3楼-- · 2019-01-10 05:56

As stated in the Laravel manual, you may roll back specific number of migrations using the --step option

php artisan migrate:rollback --step=5
查看更多
聊天终结者
4楼-- · 2019-01-10 06:02

Every time you rollback you get the last batch of migration. use the command

php artisan migrate:rollback --step=1
查看更多
劳资没心,怎么记你
5楼-- · 2019-01-10 06:06

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.

查看更多
闹够了就滚
6楼-- · 2019-01-10 06:10
INSERT INTO homestead.bb_migrations (`migration`, `batch`)  VALUES ('2016_01_21_064436_create_victory_point_balance_table', '2')

something like this

查看更多
登录 后发表回答