Skip to content
Latchkey

Elixir "(Ecto.MigrationError)" in CI

Ecto raised a migration error: migrations are pending, two share a version, or a migration uses an operation the adapter rejects. The schema could not be brought to the expected state.

What this error means

A migration or test run fails with (Ecto.MigrationError) - pending migrations, duplicate version numbers, or cannot execute ... inside transaction. It is deterministic given the migrations.

mix
** (Ecto.MigrationError) migrations can't be executed, migration
version 20260101120000 is duplicated
    (ecto_sql 3.11.0) lib/ecto/migrator.ex: ...

Common causes

Duplicate migration versions

Two migration files share the same timestamp prefix, so Ecto cannot order them and refuses to run.

Pending migrations in test

The test DB is behind the migrations; a check like Ecto.Migrator finds pending versions and raises.

Operation needs to run outside a transaction

An operation like CREATE INDEX CONCURRENTLY cannot run inside the default migration transaction.

How to fix it

Migrate the test DB before running tests

Bring the schema up to date so no migrations are pending.

CI step
MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate

Resolve version and transaction issues

  1. Give each migration a unique timestamp version.
  2. Use @disable_ddl_transaction true for concurrent operations.
  3. Run mix ecto.migrations to inspect applied vs pending.

How to prevent it

  • Generate migrations so versions stay unique.
  • Migrate the test DB in the CI setup step.
  • Flag operations that must run outside a transaction.

Related guides

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