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
- Store the connection string as a repository or environment secret.
- Map it into the job or step
env. - Run Prisma commands within that env.
.github/workflows/ci.yml
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.
.github/workflows/ci.yml
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.
Related guides
Prisma "PrismaClientInitializationError" at startup in CIFix "PrismaClientInitializationError" in CI - the client could not start because the engine, environment, or…
Prisma "P1001: Can't reach database server" (service not up) in CIFix Prisma "P1001: Can't reach database server at host:port" in CI - the database service has not started yet…
Prisma pgbouncer pooled URL needs directUrl for migrate in CIFix Prisma migrate failing against a PgBouncer pooled URL in CI - migrations need a direct connection. Set di…