Prisma "Environment variable not found: DATABASE_URL" in CI
Prisma’s datasource is configured as env("DATABASE_URL"), but that variable is absent from the process running the command. This is a configuration gap, not a database failure - there is nothing to retry.
What this error means
Any Prisma command that touches the datasource - migrate deploy, migrate dev, db push, generate with a URL - fails before connecting, naming the missing variable. It fails identically every run because the value is simply not there.
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
The workflow never sets DATABASE_URL (no env: entry, no secret reference), so the migrate step runs with it unset.
Set in one step but not exported to others
A value defined inside one shell step does not persist to later steps. Prisma in a separate step sees nothing.
Missing .env or wrong env file
Locally Prisma reads .env, but CI has no such file (or it is gitignored), so the variable is undefined on the runner.
How to fix it
Set DATABASE_URL for the job
Provide the variable at the job or step level, sourcing the value 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 in a step, write it to the job environment so later steps see it.
- run: echo "DATABASE_URL=postgresql://user:pass@db:5432/app" >> "$GITHUB_ENV"
- run: npx prisma migrate deployConfirm the variable is visible
- Add a debug step that checks the variable is set without printing its value:
test -n "$DATABASE_URL". - Ensure the secret name matches exactly - secrets are case-sensitive.
- Remember
.envis for local dev; CI must supply the variable explicitly.
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. - Add an early assertion that required env vars are set.