migration-history-inconsistent (Pro)

django.db.migrations.exceptions.InconsistentMigrationHistory: Migration auth.0001_initial is applied before its dependency contenttypes.0001_initial on database 'default'.

The migrations named in the line depend on your database. The initializer prints it as the last line of a Python traceback. dojo-deploy finds it in the initializer’s output in the start phase on Docker Compose, or the install or upgrade phase on Kubernetes, and reports Hint: migration-history-inconsistent.

Cause

The database’s migration history does not match this release. This usually happens when the application was rolled back to an earlier release without restoring the database snapshot taken with it.

Confirm

Find InconsistentMigrationHistory in the initializer’s output:

  • Docker Compose: the initializer’s full output is saved under <location>/logs/, in a file named init-failure-<date>_<time>.log. The start phase’s error names the file.

    sudo grep -l InconsistentMigrationHistory /opt/dojo/logs/init-failure-*.log   # /opt/dojo is the default location
  • Kubernetes: dojo-deploy reads the initializer Job’s output when helm ends and writes it to the log named on the Install log: or Upgrade log: line.

Recover

Restore the database snapshot that matches this release. See Restoring a backup.

Do not fake or edit migrations to get past the error. If you do not have a matching snapshot, contact DefectDojo support with this run’s log.