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:statusIn CI
.github/workflows/ci.yml
jobs:
schema-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python manage.py makemigrations --check --dry-runGotchas
--checkonly detects a missing migration, not whether it is safe; pair it with a review step.- Prisma
migrate diff --exit-codereturns 2 when a diff exists, which correctly fails the job.
Related guides
How to Test Migrations in CI (Up, Down, Reapply)Test every migration in CI against a throwaway database by applying it up, rolling it down, and reapplying it…
How to Gate a Deploy on Migration SuccessMake the app rollout depend on the migration step so a failed migration stops the deploy, keeping the code fr…