如何“不转换”南(Django)的应用程序? [英] How do I "unconvert" an app from South (Django)?

查看:109
本文介绍了如何“不转换”南(Django)的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 models.py 中改变了很多,包括删除了很多字段,并重命名了几个类。 schemamigration --auto 工作正常,但尝试迁移抛出了一大堆错误。

I changed a lot in my models.py, including deleting a lot of fields, and renaming a couple of classes. schemamigration --auto worked fine, but trying migrate threw a bunch of errors.

我的所有代码正在开发中,所以我不介意丢失数据太多。所以我想要南方unconvert或unmanage一个应用程序,所以我可以重新创建所有的表$ syncdb

All my code is currently in development so I don't mind too much losing the data. So I want South to "unconvert" or "unmanage" an app so I can rebuild all the tables with syncdb again.

或者我可以删除所有迁移列表,再次执行 schemamigration --initial

Or I could delete all migration list and do schemamigration --initial again.

推荐答案

是的,只需删除迁移并再次运行 schemamigration --initial 。在进行生产之前,您应该做正常的工作。如果您已经至少进行了一次生产,不要删除所有的迁移 - 只是在当前开发周期中创建的迁移,然后运行 schemamigration --auto 只得到一个迁移,而不是潜在的多个。

Yes, just delete the migrations and run schemamigration --initial again. You should do that anyways as normal course before moving to production. If you've already gone to production at least once, don't delete all the migrations -- just the ones you've created in the current development cycle and then run schemamigration --auto to get just one migration instead of the potential multiple ones.

FWIW,要使用南unconvert应用程序,您只需删除migrations目录,但是在这种情况下,没有必要。

FWIW, to "unconvert" an app using South, you merely delete the "migrations" directory, but in this scenario, there's no need.

更新

如果您已经迁移了您的应用程序,并删除所有迁移并生成一个新的迁移,South将抱怨仍在数据库中的迁移。您应该遵循的实际过程是:

It was pointed out that if you have already migrated your app, and you delete all the migrations and generate a single new one, South will complain about migrations still in the database. The actual process you should follow is:


  1. 回滚到您在当前开发周期中创建的最新迁移之前。例如,如果您已经在0005,并为您正在开展的开发工作(现在为0008)创建了三个新的迁移,则将回滚到0005.如果所有迁移都是新的,则回滚到

python manage.py migrate yourapp zero


  • 删除您要合并的所有迁移。在上面的例子中,这将是0006,0007和0008,或者对于一个新的应用程序,迁移目录中的所有内容都是 __ init __。py

    生成新的迁移以覆盖刚才删除的迁移。如果它是一个新的应用程序,请使用 - 初始,或者如果它是一个预先存在的应用程序,请使用 - auto

    Generate a new migration to cover the ones you just deleted. If it's a new app, use --initial, or if it was a pre-existing app, use --auto.

    python manage.py schemamigration --initial yourapp
    


  • 迁移

  • Migrate

    python manage.py migrate yourapp
    


  • 这篇关于如何“不转换”南(Django)的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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