如何重置南迁移以捕获我的django模型的当前状态

时间:2021-12-14 21:09:22

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.

我有一个应用程序,目前有35个南迁移。在设置新部署时我们需要花费一些时间(我们经常创建新的部署),并且应用程序在不断发展 - 添加更多迁移。此外,迁移包括一些可能复杂的数据迁移和一些破坏SQLite3的自定义迁移(现在不是一个大问题,因为一切都在Postgres上,但很高兴能够设置一个快速的测试环境),并且通常只是更多可能出错的事情。

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?

我们所有的部署和开发人员都是最新的,我想清除所有应用程序的迁移并创建一个捕获应用程序当前状态的初始迁移(0001),然后继续进行新的迁移那里。几年前我用不同的应用程序做了这个,并且它运行得很好,但我已经忘记了这个过程是什么,并且忘记了解释如何操作的博客文章。任何人都可以为我打破这个过程吗?

1 个解决方案

#1


13  

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!

确保在上次迁移到其他任何地方和重置之间没有添加任何新内容,否则新的0001迁移将与模式不匹配!

Caveats: See guettli's comment (and my responses)

注意事项:请参阅guettli的评论(以及我的回复)

#1


13  

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!

确保在上次迁移到其他任何地方和重置之间没有添加任何新内容,否则新的0001迁移将与模式不匹配!

Caveats: See guettli's comment (and my responses)

注意事项:请参阅guettli的评论(以及我的回复)