How to remove django migrations after squashing them?

The Django documentation says that we could remove migrations after we have served them:

You should perform this migration, but leave the old ones in place; the new migration will be used for new installations. Once you are sure that all instances of the codebase have applied the migrations you migrated, you can delete them.

Here is deleting only migration files or entries in the django_migrations table?

Here's some background: I only have a development machine, so just one code base. After serving some migrations that I have already applied, I deleted the files and database entries. Tested if it's ok by doing the migration it didn't find anything. So everything looked good. The next day I had to change something and make a migration. When I tried to migrate, it tried to apply a compressed migration (which was applied partially piece by piece before serving). So, I had to go back and re-create the records in the django_migrations table. So it seems to me that I should have been storing records in a database. I try to make sure before messing up again and understand why it looked good, and then I tried to apply a compressed migration.

+3


source to share


3 answers


Compressed migrations are never marked as applied and will be fixed in 1.8.3 (see # 24628 ).

To remove old migrations, follow these steps:



  • Make sure all superseded migrations have been applied (or none of them).
  • Delete old migration files, remove attribute replaces

    from compressed migrations.
  • (Workaround) Run ./manage.py migrate <app_label> <squashed_migration> --fake

    .

The last step is not needed when 1.8.3 arrives.

+3


source


Converting compressed migrations has become easier since the question was posted. I posted that shows how to deflate migrations using circular dependencies, and also shows how to convert a compressed migration to a regular migration after all installations have migrated past the squash point.

As Django documentation says:



Then you have to translate the compressed migration into a regular migration with:

  • Deletes all migration files it replaces.
  • Upgrading all migrations that rely on remote migrations depends on the compressed migration.
  • Removing the override attribute in the compressed migration migration class (this is how Django reports it is a compressed migration).
+1


source


I'm not an expert by any means, but I just squashed my migrations and ended up doing this:

Cancel this request to remove old migrations (compressed)

DELETE FROM south_migrationhistory;

      

Run this management command to remove ghost migrations

./manage.py migrate --fake --delete-ghost-migrations 

      

Django 1.7 also has squashmigrations

0


source







All Articles