8

I tried to squash migrations.

Unfortunately there are just too many circular dependencies.

Is there a way to start over the migrations (although my project is already deployed in production) than trying to squash the migrations?

I don't have to worry about some unknown developer using my project because it's a private project.

eugene
  • 39,839
  • 68
  • 255
  • 489

1 Answers1

15

Yes, there is a way. See this similar question. In a nusthell:

# 1) Fake migrations back to 0
./manage.py migrate app zero --fake

# 2) Delete migrations files
git rm "app/migrations/*"

# 3) Create new migration file
./manage.py makemigrations app

# 4) Pretend to run the new migration
./manage.py migrate app --fake
Community
  • 1
  • 1
Régis B.
  • 10,092
  • 6
  • 54
  • 90
  • I actually figured it might be more difficult starting over to resolve circular dependencies. (it may well depend on your migration history). but Yes that is definately the answer to my op. – eugene Feb 03 '16 at 10:57
  • Actually, when there are circular dependencies, above method would create migrations that would solve the circular dependencies automatically right? – eugene Feb 04 '16 at 05:01
  • I'm not sure what you mean by circular dependencies; do you mean migrations that depend on each other both ways? If yes, the suggested method gets rid of all migrations, thus of this kind of circular dependencies as well. – Régis B. Feb 04 '16 at 08:41
  • 1
    Yes, @eugene, the `makemigrations` command in step 3 seems to be smart enough to avoid circular dependencies between the migrations it creates. It will create more than one migration per app to avoid circular dependencies. – Don Kirkby Jun 07 '16 at 21:16
  • I've tried this on my project and I fail with circular deps across a bunch of apps. Any ideas on how to extend this to more than one app? @RégisB. – mattjegan Sep 30 '16 at 01:59
  • If this solution doesn't work for you, you probably have a different problem :) I suggest you create a new question. – Régis B. Sep 30 '16 at 16:18
  • 2
    I am guessing if you are proceeding with this method on a team project, you have to tell everyone and make sure they follow these steps (or write a git hook for this particular commit). – Forethinker Sep 06 '19 at 18:18