Skip to content
Latchkey

Django "You have N unapplied migration(s)" in CI

Django compared its migration files to the applied migrations and found some not yet applied to this database. It warns (or your check fails) because the schema is behind the migrations. This is deterministic.

What this error means

Django prints "You have N unapplied migration(s)" and your CI check or test setup fails. It happens when migrations were added but migrate was not run against the CI database first.

psql
You have 3 unapplied migration(s). Your project may not work properly
until you apply the migrations for app(s): orders.
Run 'python manage.py migrate' to apply them.

Common causes

Test database not migrated

New migration files exist but migrate was not run, so the database is behind.

makemigrations not committed

Model changes without committed migration files leave the database unable to reach the model state.

How to fix it

Run migrate before tests

Terminal
python manage.py migrate --noinput
python manage.py test

Add a migration-completeness check

  1. Run python manage.py makemigrations --check --dry-run in CI to catch missing migration files.
  2. Commit any generated migrations alongside model changes.
  3. Then migrate so the database matches the models.

How to prevent it

  • Run migrate as a setup step before the test suite.
  • Add makemigrations --check so missing migrations fail fast.
  • This is deterministic - retrying without migrating fails identically.

Frequently asked questions

What causes ""You have N unapplied migration(s)""?
New migration files exist but migrate was not run, so the database is behind.
How do I fix "You have N unapplied migration(s)"?
Run migrate before tests

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card