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.
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
- Store the connection string as a repository or environment secret.
- Map it into the job or step
env. - Run Prisma commands within that env.
jobs:
test:
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
steps:
- run: npx prisma migrate deployProvide a URL for a service database
When you start a Postgres service in CI, set DATABASE_URL to point at it explicitly.
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/app?schema=publicHow 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.