本文介绍了在 Laravel 中回滚一个特定的迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅回滚:

回滚:2015_05_15_195423_alter_table_web_directories

php artisan migrate:rollback,我的 3 个迁移正在回滚.

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


我删除

我的 web_directories 和我的 contacts 表都是无意的.我从不希望这种情况发生,如果我只能回滚那个特定的事件,那么这场灾难就永远不会发生.


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.

推荐答案

如果您查看 migrations 表,您会看到每个迁移都有一个批号.因此,当您回滚时,它会回滚上一批中的每个迁移.

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.

如果您只想回滚最后一次迁移,那么只需将批号加一.然后,下次您运行 rollback 命令时,它只会回滚该迁移,因为它属于自己的批处理".

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.

或者,从 Laravel 5.3 开始,您可以直接运行:

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.

这篇关于在 Laravel 中回滚一个特定的迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 09:03