guettli
guettli

Reputation: 27855

django.db.migrations.exceptions.InconsistentMigrationHistory: Migration ... is applied before its dependency

I get this exception:

myproject@aptguettler:~$ manage.py migrate
Traceback (most recent call last):
  File "/home/myproject/src/djangotools/djangotools/bin/manage.py", line 32, in <module>
    main()
  File "/home/myproject/src/djangotools/djangotools/bin/manage.py", line 29, in main
    execute_from_command_line()
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/myproject/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 86, in handle
    executor.loader.check_consistent_history(connection)
  File "/home/myproject/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 292, in check_consistent_history
    connection.alias,
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration myapp.0029_bar is applied before its dependency myapp.0005_foo_squashed_0028_dynamic_year on database 'default'.

My migrations:

                   name                    
-------------------------------------------
 0001_initial
 0002_...
 0003_...
 0004_...
 0005_foo
 0006_...
 0007_...
...
 0028_dynamic_year
 0029_bar
 0030_...

What could be the reason?

Upvotes: 1

Views: 722

Answers (1)

guettli
guettli

Reputation: 27855

I found the reason with the help of a team mate.

He did this:

  1. squashed migrations
  2. Production deployment and makemigrations
  3. Deleted the squashed python files in the migration directory

I updated the git repo in my (old) develoment system. Then make migrations raised above exception.

Django can't solve this, since some migrations were applied and some not and the old squashed migration files are not available any more.

I took the most simple solution: I dropped my development database and created it from scratch.

Upvotes: 1

Related Questions