agent's local prisma CLI is 5.x but the project pins 4.x - migrate diff generated SQL the old engine cant run
Fixes Prisma migrations generated with the wrong CLI version when the agent's global CLI is newer than the project's pinned version. It shows how to detect the skew, switch to the project-local CLI, and regenerate the migration with the pinned engine. Use when migrate diff output does not match what the project's Prisma version can run.
TL;DR: Never use a global Prisma CLI for project work. Check prisma --version against the version pinned in package.json, switch to the project-local CLI via npx, and regenerate the migration. Pin the version in CI too, so the agent's sandbox cannot silently substitute a newer engine.
agent's local prisma CLI is 5.x but the project pins 4.x - migrate diff generated SQL the old engine cant run- Detect the skew. Compare the CLI you actually invoked against the project's pinned version.
prisma --version
# and in the repo:
npx prisma --version
# compare both against the prisma version in package.json devDependenciesExpected: the global (or PATH-first) CLI reports 5.x while the project pins 4.x - or vice versa. You now know which binary produced the bad SQL.
- Stop using the global CLI. Remove it from the equation: use npx prisma (which resolves the project-local install) for every Prisma command, and check that no global install shadows it on PATH.
Expected: npx prisma --version reports the pinned 4.x version from inside the repo.
- Regenerate the migration SQL with the pinned CLI.
npx prisma migrate diff --from-schema-datamodel ... --to-schema-datamodel ... --scriptExpected: the regenerated SQL uses only features the 4.x engine supports.
- Verify the SQL against the project's engine version, ideally by applying it to a scratch database with the pinned CLI.
Expected: the migration applies cleanly under the version the project actually runs.
- Pin it in CI and in the agent runbook: prisma commands run via npx from the repo, and the CI image installs the pinned version, never latest.
Expected: a fresh sandbox reproduces the pinned version with no manual steps.
Use this when
- migrate diff generated SQL the project's Prisma engine cannot run
- The agent's global prisma CLI version differs from the project's pinned version
- A migration works on the agent's machine but fails in CI or production
- You see engine errors referencing SQL features your Prisma version should not emit
Not for this skill when
- Both CLIs are the same version and the SQL still fails - that is a schema or database problem, not version skew
- The project intentionally uses the global CLI and pins nothing - then standardize on one version deliberately instead
- The error is a connection or permissions problem - version skew does not cause those
- You are mid-upgrade to Prisma 5 on purpose - then upgrade the project, the engine, and the runbook together
Variant phrasings
- prisma CLI version mismatch migrate diff wrong SQL
- global prisma 5 vs project prisma 4 migration fails
- npx prisma vs global prisma different versions
- prisma migrate diff generated SQL old engine cant run
Why it happens
migrate diff output is produced by the schema engine bundled with the CLI you invoke, not by the version in package.json. A 5.x CLI happily emits SQL using engine features the project's 4.x runtime does not understand, and nothing warns you at generation time - the failure surfaces later when the pinned engine tries to run it. Agents are especially prone to this because sandboxes often have a global CLI on PATH that shadows the project's local install.
Edge cases
- pnpm and yarn PnP layouts resolve npx differently. Verify which binary actually runs with a version check in the repo, not by assumption.
- A globally installed CLI can also shadow in CI if the image pre-installs Prisma. Pin the install step to the package.json version.
- Regenerating with the old CLI can produce different SQL than the 5.x output - review the new migration file; do not just swap the header.
- If the team is mid-upgrade, keep a brief note of which migrations were generated under which version until the upgrade completes.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_xzO7tz9EF8l7EA-FfUP0SA