Ecto "pending migrations" - Database Not Migrated in CI
Ecto found migration files newer than the database’s recorded version, so it reports pending migrations. The test database was not brought up to date before the suite ran.
What this error means
The test boot or a migration check reports pending migrations and aborts. It happens in CI when migrations were added but ecto.migrate (or ecto.setup) was not run against the test database first.
Elixir output
** (Ecto.MigrationError) migrations are pending. Run `mix ecto.migrate`
to apply pending migrations for the test repo.Common causes
Test database not migrated
New migration files exist but the test database was never migrated, so Ecto sees pending migrations at boot.
ecto.setup skipped in CI
CI ran tests without ecto.create/ecto.migrate, so the database is behind the migration files.
How to fix it
Set up and migrate before tests
Create and migrate the test database as a setup step.
Terminal
MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate
mix testGuard against drift in CI
- Run
mix ecto.migrationsto see applied vs pending. - Apply the pending set with
mix ecto.migratebefore the suite. - Fail CI if migrations remain pending after setup.
How to prevent it
- Run
ecto.create+ecto.migrate(orecto.setup) before the test suite in CI. - Commit every generated migration with the code that needs it.
- Add a check that no migrations are pending after setup.
Related guides
Ecto "mix ecto.migrate" Connection Refused in CIFix Elixir "mix ecto.migrate" failing with DBConnection.ConnectionError / connection refused in CI - Postgres…
Ecto Migration Lock Timeout in CIFix Ecto migration lock waits/timeouts in CI - Ecto takes an advisory lock so one migrator runs at a time; a…
Django "makemigrations --check" Fails in CI (Missing Migrations)Fix Django "makemigrations --check --dry-run" failing in CI - a model change has no corresponding migration.…