Django South Migration Consolidation

In the initial stages of my project, I make a lot of changes in the models, and thus I have a lot of southern migrations created for my applications. Is there any way to consolidate them before moving to my production server for migrations so that I do not have a million migrations for each application? And if so, how would I do it?

+6
database django django-south
source share
2 answers

You can always delete existing migrations and create a new β€œinitial” migration .

For this you need:

  • Delete the migration files for your application (completely delete the folder)
  • Run ./manage.py convert_to_south myapp

This will leave you with one migration corresponding to the current state of your application.


In addition, you can always pack your latest migrations together:

  • Delete the migration files that you want to merge (only if they are the last). A.
  • Run ./manage.py schemamigration myapp

This will create a new migration that will correspond to remote migrations.


Both of them are likely to spoil your development database.

+5
source share

Since this is a development environment, this is how I do it (using SQLite, see below for other SQL servers):

  • Make all the changes, let the migration files pile up. No obligation migration files to VCS
  • When all new migration files are deleted
  • Rename Database
  • Run manage.py migrate. This will create the database structure, just as before you make any changes to it.
  • Run manage.py makemigrations. This will create the necessary migrations that reflect the current state.
  • Move the original database, which already has the final structure and data
  • Commit migration files

When using the "right" SQL servers, just keep two databases: production and development. Change the project settings to point to the production database instead of renaming in step 3. You can also skip step 4.

+1
source share

All Articles