Skip to content
Latchkey

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.

prisma
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

.github/workflows/ci.yml
jobs:
  migrate:
    env:
      DATABASE_URL: ${{ secrets.DATABASE_URL }}
    steps:
      - run: npx prisma migrate deploy

Export it across steps

If you compute the URL, write it to the job environment so later steps see it.

Terminal
echo "DATABASE_URL=postgresql://user:pass@localhost:5432/app" >> "$GITHUB_ENV"

How to prevent it

  • Define DATABASE_URL at the job level from a secret, not per ad-hoc step.
  • Never rely on a gitignored .env being present in CI.
  • This is deterministic - retrying without setting the variable fails identically.

Frequently asked questions

What causes ""Environment variable not found: DATABASE_URL""?
No env: entry or secret reference sets DATABASE_URL, so the step runs with it unset.
How do I fix "Environment variable not found: DATABASE_URL"?
Set DATABASE_URL for the job from a secret

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card