dtpstat/website

Prisma can't find DATABASE_URL in .env.local

Closed this issue · 2 comments

For prisma console operations, prisma checks in .env file, but not .env.local

sergous@sMacBookPro15 website % yarn prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Error: Get config: Schema Parsing P1012

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

Validation Error Count: 1

Looks like Prisma CLI does not read multiple .env files by default. They describe what to do in their docs though:
https://www.prisma.io/docs/guides/development-environment/environment-variables/using-multiple-env-files

Alternatively, we can use dotenv-flow, also via package.json. AFAIU dotenv-flow matches what Next.js does. We can try something like:

{
  "scripts": {
     "...": "...",
     "prisma": "node -r dotenv-flow/config ./node_modules/.bin/prisma",
     "...": "..."
   }
}

Commands to run should not change.

That is works, thanks. Send you RP for approval.