如何恢复上次迁移? [英] How to revert the last migration?

查看:29
本文介绍了如何恢复上次迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个迁移,添加了一个新表,但想要恢复它并删除迁移,而不创建新的迁移.

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

然后你会这样做:

./manage.py migrate my_app 0010_previous_migration 

您实际上不需要使用完整的迁移名称,数量就足够了,即

You don't actually need to use the full migration name, the number is enough, i.e.

./manage.py migrate my_app 0010 

然后您可以删除迁移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屋!

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