Prisma error: Environment variable not found: DATABASE_URL
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
- Confirm
.envexists in your project root — Prisma looks there by default, not in nested folders - Confirm the variable name matches exactly what's in your
schema.prisma'sdatasourceblock:url = env('DATABASE_URL') - Run Prisma commands from the project root, not from a subfolder — relative
.envlookup depends on your working directory
Common causes / variations
.envfile accidentally named.env.localor.env.development, which Prisma CLI doesn't read by default- Running a Prisma command inside a monorepo subpackage where the root
.envisn'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...