Prisma error: Environment variable not found: DATABASE_URL

Prisma·Sep 12, 2026·beginner·
Quick answer

Prisma can't find `DATABASE_URL` in your environment at the moment it's reading `schema.prisma` — usually because `.env` isn't in the project root, isn't loaded yet, or the variable name doesn't match exactly what's referenced in your `datasource` block.

What causes this error

Prisma CLI commands (generate, migrate, studio) read environment variables the same way any Node process does — from a loaded .env file or the shell environment. If DATABASE_URL isn't visible at that moment, this error fires before any actual database connection is attempted.

The Fix

  1. Confirm .env exists in your project root — Prisma looks there by default, not in nested folders
  2. Confirm the variable name matches exactly what's in your schema.prisma's datasource block: url = env('DATABASE_URL')
  3. Run Prisma commands from the project root, not from a subfolder — relative .env lookup depends on your working directory

Common causes / variations

  • .env file accidentally named .env.local or .env.development, which Prisma CLI doesn't read by default
  • Running a Prisma command inside a monorepo subpackage where the root .env isn't visible
  • CI/CD pipeline not injecting the environment variable before the Prisma step runs

Related errors

See also: PrismaClientInitializationError, drift detected.

Was this fix helpful?

Comments

Loading comments...