laravel 回滚单表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20259105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:42:40  来源:igfitidea点击:

Rollback single table

laravellaravel-4

提问by Rajat

How to rollback the single table in laravel 4. I ran php artisan migrate:rollbackto roll back all the migrations but how to rollback the single table

Laravel 4中如何回滚单表,我跑回php artisan migrate:rollback滚了所有的迁移但是如何回滚单表

Advice much appreciated

非常感谢建议

回答by Andres Felipe

for example, you want to create the user table again, just go to mysql and delete from migration's table the field that correspond to TIMESTAMP_create_users_table:

例如,你想再次创建用户表,只需去mysql并从迁移表中删除与TIMESTAMP_create_users_table对应的字段:

DELETE FROM MIGRATIONS WHERE MIGRATION ="2014_10_12_000000_create_users_table";

and drop the users table too:

并删除用户表:

DROP TABLE users;

after that, just run

之后,只需运行

php artisan migrate

and that's it!

就是这样!

回答by Ronald Hulshof

If you wish to rollback only a specific table, you should make a migration that only includes that table. It's really that simple. Making large migrations covering several updates doesn't make any sense.

如果您只想回滚特定表,则应进行仅包含该表的迁移。真的就是这么简单。进行涵盖多个更新的大型迁移没有任何意义。

Create migrations based upon their purpose. That means; on a live project every little code change should have its own related migration.

根据目的创建迁移。这意味着;在实时项目中,每个小的代码更改都应该有自己的相关迁移。

回答by HeadAndTail

Just run The command (Laravel 5):-

只需运行命令(Laravel 5):-

php artisan migrate:rollback --step=5

It will undo last 5 migrations (in fact it will execute the function "down" in each one)

它将撤消最后 5 次迁移(实际上它会在每个迁移中执行“down”函数)

php artisan migrate

It will add all migration table into database

它将所有迁移表添加到数据库中