Prisma "Environment variable not found: DATABASE_URL" in CI
Prisma's datasource is env("DATABASE_URL"), but that variable is absent from the process running the command. Nothing connected; this is a configuration gap with nothing to retry.
What this error means
Any Prisma command that touches the datasource fails before connecting, naming the missing variable. It fails identically every run because the value is simply not present.
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:3
|
2 | provider = "postgresql"
3 | url = env("DATABASE_URL")Common causes
Variable not defined in the CI job
No env: entry or secret reference sets DATABASE_URL, so the step runs with it unset.
Set in one step, not exported to others
A value defined inside one shell step does not persist; Prisma in a later step sees nothing.
Relying on a gitignored .env
Locally Prisma reads .env, but CI has no such file, so the variable is undefined.
How to fix it
Set DATABASE_URL for the job from a secret
jobs:
migrate:
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
steps:
- run: npx prisma migrate deployExport it across steps
If you compute the URL, write it to the job environment so later steps see it.
echo "DATABASE_URL=postgresql://user:pass@localhost:5432/app" >> "$GITHUB_ENV"How to prevent it
- Define
DATABASE_URLat the job level from a secret, not per ad-hoc step. - Never rely on a gitignored
.envbeing present in CI. - This is deterministic - retrying without setting the variable fails identically.