7

I have 82 migration files in my django app. Some of them are related to removed models. I want to merge all these 82 migration files into one migration file.

How do I do without deleting the database?

1 Answers1

9

The django documentation has a section devoted to this.

From the documentation page:

./manage.py squashmigrations myapp 0004

Where myapp is the name of your application, and 0004 is the migration to squash up to.

damon
  • 14,485
  • 14
  • 56
  • 75
Shadow
  • 8,749
  • 4
  • 47
  • 57
  • 3
    And dont forget to **make a backup before**. – Olivier Pons Oct 02 '17 at 07:11
  • 1
    @OlivierPons Why? Squashing migrations doesn't delete any files - it just creates a 'shortcut' migration that contains all of the steps you squashed. – Shadow Oct 02 '17 at 22:04
  • 2
    A database backup. I dont remember why, but I know it's possible to make a mistake - I surely did. Not Django, but me. Just believe an old geek: it's much safer to always make a backup of everything: files and database. `;^)` – Olivier Pons Oct 03 '17 at 14:13
  • 1
    I agree that it safer - but this operation doesn't do anything to existing files or database. Sure, if you want to make a backup go ahead though... just wasn't sure that the bold was really justified in this instance. – Shadow Oct 04 '17 at 21:56