如何还原上一次迁移? [英] How to revert the last migration?
本文介绍了如何还原上一次迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经进行了迁移,添加了一个新表,并希望还原该表并删除该迁移,而不创建新迁移。
I've made a migration that added a new table and want to revert it and delete the migration, without creating a new migration.
我该怎么做?是否有命令还原上一次迁移,然后我可以简单地删除迁移文件?
How do I do it? Is there a command to revert last migration and then I can simply delete the migration file?
推荐答案
您可以通过迁移到
例如,如果您最近的两次迁移是:
For example, if your last two migrations are:
-
0010_previous_migration
-
0011_migration_to_revert
0010_previous_migration
0011_migration_to_revert
然后您将执行以下操作:
Then you would do:
./manage.py migrate my_app 0010_previous_migration
然后您可以删除迁移 0011_migration_to_revert
。
如果使用的是Django 1.8+,则可以显示所有迁移的名称
If you're using Django 1.8+, you can show the names of all the migrations with
./manage.py showmigrations my_app
要撤消某个应用程序的所有迁移,您可以运行:
To reverse all migrations for an app, you can run:
./manage.py migrate my_app zero
这篇关于如何还原上一次迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文