问题描述
我有一个应用程序,目前有35个南移。在设置新的部署(我们经常创建新的部署)时,需要一段时间才能完成,应用程序不断发展 - 增加更多迁移。此外,迁移包括一些潜在的复杂数据迁移和一些破坏SQLite3的自定义迁移(现在不是一个巨大的问题,因为一切都在Postgres上,但是很高兴能够设置一个快速的测试环境),一般只是更多可能出错的事情我们所有的部署和开发人员都是最新的,我想清除所有应用的迁移,并创建一个初始迁移(0001),捕获应用程序的当前状态,然后从那里进行新的迁移。我在几年前用不同的应用程序做了这个工作,并且很好地实现了,但是我已经忘记了这个过程是什么,失去了对博客文章的追踪,解释了如何做到这一点。任何人都可以为我分解这个过程?
我想到了(不是太糟糕)。要设置迁移重置,请执行以下操作:
rm< app-dir> / migrations / *
python manage.py schemamigration< app-name> --initial
python manage.py migrate< app-name> 0001 - fake --delete-ghost-migrations
我将更改提交到存储库,然后对于每个部署其他地方的代码,运行:
python manage.py migrate< app-name> 0001 - fake --delete-ghost-migrations
确保您不要在你最后迁移到别处的时间,你重置的东西或新的0001迁移将不符合模式!
注意事项:请参阅guettli的评论(和我的回复)
I have an app that currently has 35 south migrations. These take a while to go through when setting up a new deployment (we create new deployments often), and the app is continually evolving--adding more migrations. Additionally, the migrations include some potentially complex data migrations and a few custom migrations that break SQLite3 (not a huge problem right now since everything is on Postgres, but its nice to be able to set up a quick test environment), and generally just more things that can go wrong.
All of our deployments and developers are up to date, and I'd like to clear out all of the app's migrations and create a single initial migration (0001) that captures the current state of the app, and then go forward with new migrations from there. I did this a few years ago with a different app, and it worked out nicely, but I've since forgotten what the process was and lost track of the blog post that explained how to do it. Can anyone break down this process for me?
I figured this out (wasn't too bad). To set up the migration reset, I do the following:
rm <app-dir>/migrations/*
python manage.py schemamigration <app-name> --initial
python manage.py migrate <app-name> 0001 --fake --delete-ghost-migrations
I commit the changes to the repository, and then for each deployment of the code elsewhere, run:
python manage.py migrate <app-name> 0001 --fake --delete-ghost-migrations
Make sure you don't add anything new between the time you last migrated everywhere else and you reset things or the new 0001 migration won't match up with the schema!
Caveats: See guettli's comment (and my responses)
这篇关于如何重新设置南方迁移以捕获我的django模型的当前状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!