TNN
TNN

Reputation: 421

Best way to squash migrations django

I had 10 migrations and I wanted to keep them in one file . So I squash them using ./manage.py squashmigrations accounts . Now I had 11 files including init and squash file. so I deleted 9 other files and kept init and squash and run migration and migrate .

Now want to ask Is this proper way ? and I have another app with same scenario should I do same to that ?

Upvotes: 3

Views: 4160

Answers (1)

David
David

Reputation: 94

Yes that's basically the way to do it :) Django has a great documentation about how to squash migrations and the appropriate workflow. See https://docs.djangoproject.com/en/3.1/topics/migrations/#migration-squashing

In short,

  1. Create a squash migration and add it to your other migrations
  2. Once you applied all current migrations to your environment(s), you can delete the old files as you did.

But additionally, you should

  1. make sure other apps that referenced a deleted migration are updated to link to your new squash migration file
  2. delete the replaces attribute inside of the squash migration, so that it is considered as a plain migration (and not a squash migration anymore)

Then you're done and you can repeat the process for other apps, the same one again once more migrations accumulated again.

Upvotes: 4

Related Questions