1

I have some questions on Squashing in Django 1.8. I've squashed a few migration files into one but not quite sure how to do the 2 actions as specified in the djangoprojects docs.

After this has been done, you must then transition the squashed migration to a normal initial migration, by:

-Deleting all the migration files it replaces

-Removing the replaces argument in the Migration class of the squashed migration (this is how Django tells that it is a squashed migration)

  1. Do I just delete the migration files in the migration file using normal rm command?
  2. Do I just vim the migration file "0001_squashed_xxx" and remove the part "replaces = []"?
  3. Also, after I run the squashed migration, the migration (original is 0010) became 0001 automatically. Is this the expected behavior?

Any help would be great. Thanks!

Community
  • 1
  • 1
SimonK
  • 73
  • 1
  • 5

1 Answers1

1
  1. Do I just delete the migration files in the migration file using normal rm command?
  2. Do I just vim the migration file "0001_squashed_xxx" and remove the part "replaces = []"?

Yes and yes, but only AFTER you've run the squashed migrations on all your production sites. Also, you should ensure that none of your other migrations depend on the migrations you're about to delete. If they do, you should change those dependencies to point at the corresponding squashed migrations instead.

  1. Also, after I run the squashed migration, the migration (original is 0010) became 0001 automatically. Is this the expected behavior?

This is because squashed migrations are given the name <start_migration>_squashed_<end_migration>. So if you squashed from 0001_initial to 0010_blah, the squashed migration will have the name 0001_initial_squashed_0010_blah and thus its code will start with 0001. But the numbering doesn't really mean anything, it's just there so that your migrations are nicely ordered when listed in a directory.

jarekwg
  • 375
  • 3
  • 8
  • Thanks. Forgotten about this question. I have done this multiple times now by using the 3 steps. No issue so far. I guess it is the correct way to squash migrations. Thanks anyway jarekwg! – SimonK Feb 12 '16 at 12:53