Skip to content
Latchkey

How to Detect Missing Migrations in CI

A model change merged without its migration causes runtime drift; a check step fails CI when the schema and migrations disagree.

Most ORMs can compare the declared models against the migration history and exit non-zero if a migration is missing. Run that check in CI so a pull request that changes a model but forgets the migration fails before merge.

Check per tool

Terminal
# Django: fails if a model change has no migration
python manage.py makemigrations --check --dry-run

# Prisma: fails if the schema drifts from migrations
npx prisma migrate diff \
  --from-migrations ./prisma/migrations \
  --to-schema-datamodel ./prisma/schema.prisma \
  --exit-code

# Rails: fails if there are pending migrations
bin/rails db:migrate:status

In CI

.github/workflows/ci.yml
jobs:
  schema-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: python manage.py makemigrations --check --dry-run

Gotchas

  • --check only detects a missing migration, not whether it is safe; pair it with a review step.
  • Prisma migrate diff --exit-code returns 2 when a diff exists, which correctly fails the job.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →