Skip to content
Latchkey

Nx "nx migrate" failed to apply in CI

The nx migrate flow writes a migrations.json, then nx migrate --run-migrations applies each package migration. A failure means one migration threw, or the run was invoked without the generated migrations.json present.

What this error means

A migrate step fails with a stack trace from a specific migration, or reports it cannot find migrations.json to run.

Nx
NX   The migrate command failed.
Cannot find migrations file "migrations.json". Run "nx migrate" first.

Common causes

run-migrations without a migrations.json

nx migrate <version> generates migrations.json; running --run-migrations without that file present fails because there is nothing to apply.

A migration threw against the current state

An individual package migration failed because the workspace does not match its expected shape or versions are mismatched.

How to fix it

Generate then run migrations in order

  1. Run nx migrate <version> to update package.json and write migrations.json.
  2. Install dependencies so the new versions are present.
  3. Run nx migrate --run-migrations to apply them.
Terminal
nx migrate latest
npm install
nx migrate --run-migrations

Read the failing migration

The trace names which package migration threw. Fix the workspace state it expected, or skip and apply it manually.

How to prevent it

  • Run migrate in the documented order: generate, install, then run.
  • Commit or keep migrations.json for the run step in the same job.
  • Upgrade Nx core and plugins together to matching versions.

Related guides

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