Skip to content
Latchkey

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 test

Guard against drift in CI

  1. Run mix ecto.migrations to see applied vs pending.
  2. Apply the pending set with mix ecto.migrate before the suite.
  3. Fail CI if migrations remain pending after setup.

How to prevent it

  • Run ecto.create + ecto.migrate (or ecto.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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →