PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 14, 2022

[FIXED] How to delete django migrations after squashing them?

 April 14, 2022     django, django-migrations, migration, squash     No comments   

Issue

Django documentation says we could delete migrations after squashing them:

You should commit this migration but leave the old ones in place; the new migration will be used for new installs. Once you are sure all instances of the code base have applied the migrations you squashed, you can delete them.

Here, does deleting means deleting only the migration files, or the entries in the django_migrations table as well?

Here is some background: I have only the development machine, so just one code base. After squashing some of the migrations that I had already applied, I deleted the files and the database entries. Tested if this is OK by making migrations, it did not find anything. So, everything looked good. Next day, I had to change something, and made migration. When I tried to migrate, it tried to apply the squashed migration too (which was applied part by part before being squashed). So, I had to go back and recreate the entries in the django_migrations table. So, it seems like I had to keep the database entries. I am trying to make sure before I mess up anything again, and understand why it looked fine first, and then tried to apply the squashed migration.


Solution

Squashed migrations are never marked as applied, which will be fixed in 1.8.3 (see #24628).

The steps to remove the old migrations are:

  1. Make sure all replaced migrations are applied (or none of them).
  2. Remove the old migration files, remove the replaces attribute from the squashed migrations.
  3. (Workaround) Run ./manage.py migrate <app_label> <squashed_migration> --fake.

The last step won't be necessary when 1.8.3 arrives.



Answered By - knbk
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing