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.
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
python manage.py migrate --noinput
python manage.py testAdd a migration-completeness check
- Run
python manage.py makemigrations --check --dry-runin CI to catch missing migration files. - Commit any generated migrations alongside model changes.
- Then
migrateso the database matches the models.
How to prevent it
- Run
migrateas a setup step before the test suite. - Add
makemigrations --checkso missing migrations fail fast. - This is deterministic - retrying without migrating fails identically.