v0 chat uses production environment variables and fails to create NeonDB branch

Problem

When creating a new chat for an existing project running on Vercel using the NeonDB integration, a new git branch is created as expected, safeguarding main. However, the chat still uses the same production environment variables the app is running with in production.

Current Behavior

  • No new NeonDB branch is created (though it works fine when creating a new branch outside of v0).
  • VERCEL_ENV and NEXT_PUBLIC_VERCEL_ENV are not set to preview or development as expected.
  • This is dangerous because the development environment pushes migrations on start, which could break production.

The release article does mention new Neon branch creations so I assume something is going wrong on our side or Vercel’s: The New v0 Is Ready for Production Apps and Agents - Neon

Question

How can we proceed to debug this issue?

Hi Vsme,

I’d treat this as a potentially risky env/branch-mapping issue and disable any automatic migration-on-start behavior until you confirm which database the v0 chat is actually using.

A safe way to debug it is to log only the environment and Neon host/branch, not the full connection string or password:

console.log({
  vercelEnv: process.env.VERCEL_ENV,
  publicVercelEnv: process.env.NEXT_PUBLIC_VERCEL_ENV,
  databaseHost: process.env.DATABASE_URL
    ? new URL(process.env.DATABASE_URL).host
    : "missing",
})

If the v0 chat/preview shows production or points at the same Neon host/branch as production, then I would not run migrations from that environment.

In Vercel, I’d also check:

Project Settings → Environment Variables

and confirm whether DATABASE_URL / POSTGRES_URL have separate values for Production and Preview. Preview env vars are used for non-production branches, and branch-specific Preview values can override the general Preview value.

Neon’s Vercel preview integration is supposed to create a preview/<git-branch> branch and inject the connection string into that deployment, so if that branch is not being created, I’d check the Neon integration events and branch limit first:

For now, I’d make the app defensive:

if (process.env.VERCEL_ENV === "production") {
  // never run dev/reset/auto migrations here
}

and only allow destructive or auto migrations when an explicit non-production flag is set, for example ALLOW_PREVIEW_MIGRATIONS=true.

Can you share whether the v0 chat is connected to a Git branch that creates a normal Vercel Preview Deployment, or whether it is running only inside the v0 preview/chat environment?