Your AI agent changed the Prisma schema, and Vercel keeps deploying the old client until you regenerate it on every build

Vercel caches dependencies, so a stale Prisma Client can survive a schema change. Add a postinstall script that runs prisma generate, and fix the prisma: command not found variant.

انتقل إلى الإصلاح
في هذه الصفحة

Your AI agent added a new model or column to schema.prisma. Locally everything works. After you deploy to Vercel, the app throws errors about a missing field or model, as if your schema change never happened. In the other variant, the build itself fails with prisma: command not found.

Your code is fine. The deployed app is running a Prisma Client generated from an older schema, or no generated client is being built at all.

Why this happens

Prisma Client is generated code. It is created by prisma generate from your schema, and your code only knows about the models in the last generated copy. The Prisma Vercel deployment guide explains the trap: Vercel caches dependencies between builds, and that “may result in an outdated version of Prisma Client on a change in your Prisma schema.”

So the sequence is: the agent edits the schema, you push, Vercel restores cached node_modules with the old generated client, and the build never regenerates it. The other error has a different cause. The guide says prisma: command not found means “you are missing prisma in your dependencies”, and because prisma is a dev dependency by default, a build that skips dev dependencies cannot run it.

How to tell if this is your problem

  1. Read the Vercel build log. If you see prisma: command not found, jump to the second fix below.
  2. Check your package.json scripts. If there is no postinstall that runs prisma generate, and your build script does not run it either, the client is only regenerated on your own machine.
  3. Compare timing. If the app broke right after a schema change and a redeploy with the build cache cleared fixes it, the cached client was the cause.

The fix

Regenerate the client on every install. Add this to package.json, as the Prisma guide recommends:

{
  "scripts": {
    "postinstall": "prisma generate"
  }
}

The guide’s wording: this “will re-generate Prisma Client at build time so that your deployment always has an up-to-date client.”

If the log says prisma: command not found, move prisma from devDependencies into dependencies, then commit the updated package.json and lockfile together.

Two things this does not do:

  • It does not change your database. prisma generate only builds the client. A new column still needs a migration applied to the production database, which is a separate step.
  • It does not fix a client that was already deployed. Push a new commit so the build runs again.

How to avoid this next time

Add a rule to your agent’s instructions: “When you change schema.prisma, confirm package.json has a postinstall script that runs prisma generate, and tell me whether a migration is needed for the production database.” In review, treat a schema change with no matching migration as unfinished.

Comments