How to reset south migrations to capture the current state of my django models

对着背影说爱祢 提交于 2019-12-03 06:20:39

问题


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?


回答1:


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)



来源:https://stackoverflow.com/questions/12822584/how-to-reset-south-migrations-to-capture-the-current-state-of-my-django-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!