Skip to content
Latchkey

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.

prisma output
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.

.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 in a step, write it to the job environment so later steps see it.

.github/workflows/ci.yml
- run: echo "DATABASE_URL=postgresql://user:pass@db:5432/app" >> "$GITHUB_ENV"
- run: npx prisma migrate deploy

Confirm the variable is visible

  1. Add a debug step that checks the variable is set without printing its value: test -n "$DATABASE_URL".
  2. Ensure the secret name matches exactly - secrets are case-sensitive.
  3. Remember .env is for local dev; CI must supply the variable explicitly.

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.
  • Add an early assertion that required env vars are set.

Frequently asked questions

What causes ""Environment variable not found: DATABASE_URL""?
The workflow never sets DATABASE_URL (no env: entry, no secret reference), so the migrate step runs with it unset.
How do I fix "Environment variable not found: DATABASE_URL"?
Provide the variable at the job or step level, sourcing the value 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