Skip to content
Latchkey

Prisma "Environment variable not found: DATABASE_URL" in CI

Prisma resolves env("DATABASE_URL") from the datasource block at load time. If the variable is not set in the step that runs Prisma, validation fails before any query runs.

What this error means

A migrate, generate, or app step fails with "error: Environment variable not found: DATABASE_URL." even though the secret exists in the repository settings.

Prisma
Error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:8
   |
 7 |   provider = "postgresql"
 8 |   url      = env("DATABASE_URL")

Common causes

The secret was not exposed to the step

A repository secret exists but is not mapped into env for the job or step, so the process cannot see DATABASE_URL.

A .env file that is not present in CI

Local runs read .env, but that file is gitignored and absent on the runner, leaving the variable unset.

How to fix it

Inject the URL from a secret

  1. Store the connection string as a repository or environment secret.
  2. Map it into the job or step env.
  3. Run Prisma commands within that env.
.github/workflows/ci.yml
jobs:
  test:
    env:
      DATABASE_URL: ${{ secrets.DATABASE_URL }}
    steps:
      - run: npx prisma migrate deploy

Provide a URL for a service database

When you start a Postgres service in CI, set DATABASE_URL to point at it explicitly.

.github/workflows/ci.yml
env:
  DATABASE_URL: postgresql://postgres:postgres@localhost:5432/app?schema=public

How to prevent it

  • Map every Prisma step to a job/step env with the connection string.
  • Do not depend on a gitignored .env in CI.
  • Keep the secret name identical to the env var Prisma reads.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →