South migration: delete all migration files (00*_*) and start from 0001, while keeping the original data

时光总嘲笑我的痴心妄想 提交于 2019-12-23 17:13:00

问题


I am developing web systems using Django and they are deployed on Heroku. After the system goes production, all database data and the migration files (i.e., the 00*_* files) have to be retained. The followings are my procedure to perform database migration and deployment:

  1. For the first deployment, perform manage.py makemigrations locally and push to Heroku.

  2. Perform manage.py migrate on Heroku.

If models are changed later:

  1. Perform makemigrations locally and push to Heroku.

  2. Perform migrate on Heroku.

Steps 3 and 4 are repeated if models are changed.

As the system evolves, there are more and more migration files. I am wondering: after a successful migration and deployment, can I just delete all migration files and start like a fresh one? That is:

  1. For the first deployment, perform makemigration locally and push to Heroku.

  2. Perform migrate on Heroku.

  3. Delete all local migration files.

  4. Perform makemigrations locally to create seemingly start-up migration files.

Change models:

  1. Perform makemigration locally and push to Heroku.

  2. Perform migrate on Heroku.

Steps 3 to 6 are repeated if models are changed.

Is the above procedure correct?


回答1:


For each of your app:

1) Pretend to rollback all existing migrations:

./manage.py migrate app zero --fake

The zero argument indicates that we rollback to the first migration. You can confirm all migrations have been rollbacked by running ./manage.py migrate app --list. The --fake option signals we should not actually run the migrations, but nonetheless mark the migrations as having been run: https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake

2). Delete migration files

git rm app/migrations/*

3) Create a new migration file

./manage.py makemigrations app

4) Pretend to run the new migration

./manage.py migrate app --fake

As in 1), step 4) does not actually run the migrations.

EDIT: added some explanations and fixed the zero argument.



来源:https://stackoverflow.com/questions/32074791/south-migration-delete-all-migration-files-00-and-start-from-0001-while-k

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