Prisma "Environment variable not found: DATABASE_URL" in CI
Your schema.prisma datasource reads url = env("DATABASE_URL"), and when Prisma loaded the schema that variable was not set in the step's environment. Prisma validates the datasource before connecting, so it fails before any database work.
What this error means
prisma migrate or prisma generate fails with "Environment variable not found: DATABASE_URL." pointing at the datasource block in schema.prisma.
Error: Environment variable not found: DATABASE_URL.
--> prisma/schema.prisma:7
|
6 | provider = "postgresql"
7 | url = env("DATABASE_URL")Common causes
The variable is not exported in the migrate step
A secret or env was set in one step or job but not in the step that runs Prisma, so env("DATABASE_URL") resolves to nothing.
Prisma did not load the .env file
Prisma auto-loads .env only from the project root (or the schema folder). In CI the value usually comes from the workflow env, and a missing or wrongly-scoped definition leaves it unset.
How to fix it
Set DATABASE_URL for the step
Provide the variable in the workflow env (from a secret) so it is present when Prisma loads the schema.
- run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}Confirm Prisma can see it
- Echo a non-secret marker (not the value) to confirm the env is set in that step.
- Make sure the variable name matches
env("DATABASE_URL")exactly, including case. - If you rely on
.env, ensure it sits next to the schema or is loaded withdotenvbefore the command.
How to prevent it
- Define DATABASE_URL at the job or step env from a CI secret.
- Keep the env var name identical to the one referenced in schema.prisma.
- Do not depend on a local .env that is not committed or generated in CI.