django还原最后一次迁移 [英] django revert last migration

查看:456
本文介绍了django还原最后一次迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了迁移,添加了一个新表,并希望将其还原并删除迁移,而不会创建新的迁移。



我该怎么做?是否有命令恢复最后的迁移,然后我可以简单地删除迁移文件?

解决方案

您可以通过迁移到以前的迁移。



例如,如果最后两次迁移是:




  • 0010_previous_migration

  • 0011_migration_to_revert



然后你会做:

  ./ manage.py migrate my_app 0010_previous_migration 

然后,您可以删除迁移 0011_migration_to_revert 。 p>

如果您使用的是Django 1.8+,您可以使用

显示所有迁移的名称 ./ manage.py showmigrations my_app 

要反转应用程序的所有迁移,您可以运行:

  ./ manage.py migrate my_app zero 


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?

解决方案

You can revert by migrating to the previous migration.

For example, if your last two migrations are:

  • 0010_previous_migration
  • 0011_migration_to_revert

Then you would do:

./manage.py migrate my_app 0010_previous_migration 

You can then delete migration 0011_migration_to_revert.

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

这篇关于django还原最后一次迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆