South: delete all migration files (00 * _ *) and start at 0001, preserving the original data

I develop web systems using Django and they are deployed to Heroku. After starting the system, all database data and migration files (i.e. Files 00 * _ *) must be saved. The following is my procedure for migrating and deploying a database:

  • For the first deployment, run manage.py makemigrations locally and click on Heroku.

  • Run manage.py migrate on Heroku.

If models are changed later:

  1. Perform makemigrations locally and click on Heroku.

  2. Run migrate to Heroku.

Steps 3 and 4 are repeated if the models are changed.

As the system evolves, more and more migration files. I am wondering: after a successful migration and deployment, can I just delete all the migration files and start as new? I.e:

  • For the first deployment, run makemigration locally and click on Heroku.

  • Run migrate to Heroku.

  • Delete all local migration files.

  • Perform makemigrations locally to create seemingly migration files at startup.

Change models:

  1. Run makemigration locally and click on Heroku.

  2. Run migrate to Heroku.

Steps 3 through 6 are repeated if the models are changed.

Is this procedure correct?

+3
source share
1 answer

For each of your applications:

1) Pretend rollback of all existing moves:

 ./manage.py migrate app zero --fake 

The zero argument indicates that we are rolling back the first migration. You can confirm that all migrations have been discarded by running ./manage.py migrate app --list . The signals of the --fake option we should not start the migration, but nevertheless note that the migrations were performed: 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) Imagine to perform a new migration

 ./manage.py migrate app --fake 

As in 1), stage 4) does not actually perform migration.

EDIT: some clarification added and zero argument fixed.

+3
source

Source: https://habr.com/ru/post/1242184/


All Articles