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 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
- Run
nx migrate <version>to updatepackage.jsonand writemigrations.json. - Install dependencies so the new versions are present.
- Run
nx migrate --run-migrationsto apply them.
nx migrate latest
npm install
nx migrate --run-migrationsRead 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.jsonfor the run step in the same job. - Upgrade Nx core and plugins together to matching versions.