返回 Discover
Field DispatchStack Overflow10 · 2026-05-28

Prisma db push cannot find DATABASE_URL when .env is in parent directory

Tags
postgresqlnext.jsprismasupabase.env
Score
0
Answers
0
Views
78
Answered
No
痛点分析发布于 2026/05/27

痛点为 AI 基于上游原始证据的初步提炼;未包含额外中国市场检索。

痛点

用户在 Next.js 项目中同时使用 Prisma 和 Supabase,将 .env 文件放在项目根目录以实现单一环境变量源,但 Prisma CLI 在执行 db push 时无法读取父目录的 .env,导致 DATABASE_URL 未找到而报错。用户原本期望通过根目录 .env 统一管理配置,避免重复维护,但 Prisma 的默认行为只读取当前工作目录下的 .env,造成配置加载失败。这迫使开发者要么在子目录中重复定义变量(破坏单一事实源),要么引入 dotenv-cli 等额外工具(增加复杂度)。对于使用 monorepo 或分层结构的项目,这种环境变量继承缺失会导致频繁的配置调试和构建失败,浪费开发时间并增加协作成本。

§ Dossier

Stack Overflow question

I am working on a NEXT.js project that uses Prisma and Supabase Postgres.My project structure is: Directory structure: └── lunartech-x-dark-phoenix/ ├── ai-podcast-clipper-backend/ │ ├── requirements.txt │ ├── ytdownload.py │ └── asd/ │ └── model/ │ └── faceDetector/ │ ├── README.md │ └── __init__.py └── ai-podcast-clipper-frontend/ ├── add-credits.js ├── components.json ├── next.config.js ├── postcss.config.js ├── prettier.config.js ├── tsconfig.json └── src/ ├── app/ │ ├── layout.tsx │ ├── api/ │ │ ├── auth/ │ │ │ └── [...nextauth]/ │ │ │ └── route.ts │ │ └── inngest/ │ │ └── route.ts │ ├── dashboard/ │ │ ├── layout.tsx │ │ └── loading.tsx │ ├── login/ │ │ └── page.tsx │ └── signup/ │ └── page.tsx ├── components/ │ └── ui/ │ ├── input.tsx │ ├── label.tsx │ └── sonner.tsx ├── inngest/ │ └── client.ts ├── lib/ │ ├── auth.ts │ └── utils.ts ├── schemas/ │ └── auth.ts └── server/ ├── db.ts └── auth/ └── index.ts The root .env file is supposed to be the single source of environment variables for the whole project. In .env , I have: DATABASE_URL="postgresql://postgres.PROJECT_REF:MY_PASSWORD@aws-1-ap-southeast-2.pooler.supabase.com:5432/postgres" My prisma schema has: datasource db { provider = "postgresql" url = env("DATABASE_URL") } When I run this command from the frontend folder: cd ai-podcast-clipper-frontend npm run db:push The script runs: prisma db push But I get this error: PS E:\LunarTechTakeHomeAssignment(DarkPhoenix)\DARK-PHOENIX\ai-podcast-clipper-frontend> npm run db:push > ai-podcast-clipper-frontend@0.1.0 db:push > prisma db push Prisma schema loaded from prisma\schema.prisma Error: Prisma schema validation - (get-config wasm) Error code: P1012 error: Environment variable not found: DATABASE_URL. --> prisma\schema.prisma:14 | 13 | // https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string 14 | url = env("DATABASE_URL") | Validation Error Count: 1 [Context: getConfig] Prisma CLI Version : 6.7.0 The Next.js config loads the parent .env using loadEnvConfig("..") , but it seems Prisma CLI does not load the parent .env when I run prisma db push. Should I duplicate DATABASE_URL inside ai-podcast-clipper-frontend/.env , or should I use something like dotenv-cli ? What is the cleanest way to make prisma db push read ../.env ? For a Supabase connection string, should [YOUR-PASSWORD] include the square brackets, or should I replace the whole placeholder? I am using: Prisma CLI: 6.7.0 Node.js: 20+ Windows PowerShell Supabase Postgres Next.js frontend I want to keep the root .env as the single source of truth if possible. If there is any issue with my Supabase connection, I tried using both Direct Connection and Session Pooler connection. The associated repository link is : https://github.com/LUNARTECH-X/DARK-PHOENIX

§ Dossier

Question details

View count
78
Answer count
0
Last activity
2026/05/23
源数据· Raw Archive
source
Stack Overflow
upstream_source
stackoverflow
upstream_item_id
79945585
daily_ranking_item_id
1ff729e7-9ca9-4c53-802a-8e97def0df70
rank_date
2026-05-28
rank
10
name
Prisma db push cannot find DATABASE_URL when .env is in parent directory
tagline
postgresql, next.js, prisma, supabase, .env
description
I am working on a NEXT.js project that uses Prisma and Supabase Postgres.My project structure is: Directory structure: └── lunartech-x-dark-phoenix/ ├── ai-podcast-clipper-backend/ │ ├── requirements.txt │ ├── ytdownload.py │ └── asd/ │ └── model/ │ └── faceDetector/ │ ├── README.md │ └── __init__.py └── ai-podcast-clipper-frontend/ ├── add-credits.js ├── components.json ├── next.config.js ├── postcss.config.js ├── prettier.config.js ├── tsconfig.json └── src/ ├── app/ │ ├── layout.tsx │ ├── api/ │ │ ├── auth/ │ │ │ └── [...nextauth]/ │ │ │ └── route.ts │ │ └── inngest/ │ │ └── route.ts │ ├── dashboard/ │ │ ├── layout.tsx │ │ └── loading.tsx │ ├── login/ │ │ └── page.tsx │ └── signup/ │ └── page.tsx ├── components/ │ └── ui/ │ ├── input.tsx │ ├── label.tsx │ └── sonner.tsx ├── inngest/ │ └── client.ts ├── lib/ │ ├── auth.ts │ └── utils.ts ├── schemas/ │ └── auth.ts └── server/ ├── db.ts └── auth/ └── index.ts The root .env file is supposed to be the single source of environment variables for the whole project. In .env , I have: DATABASE_URL="postgresql://postgres.PROJECT_REF:MY_PASSWORD@aws-1-ap-southeast-2.pooler.supabase.com:5432/postgres" My prisma schema has: datasource db { provider = "postgresql" url = env("DATABASE_URL") } When I run this command from the frontend folder: cd ai-podcast-clipper-frontend npm run db:push The script runs: prisma db push But I get this error: PS E:\LunarTechTakeHomeAssignment(DarkPhoenix)\DARK-PHOENIX\ai-podcast-clipper-frontend> npm run db:push > ai-podcast-clipper-frontend@0.1.0 db:push > prisma db push Prisma schema loaded from prisma\schema.prisma Error: Prisma schema validation - (get-config wasm) Error code: P1012 error: Environment variable not found: DATABASE_URL. --> prisma\schema.prisma:14 | 13 | // https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string 14 | url = env("DATABASE_URL") | Validation Error Count: 1 [Context: getConfig] Prisma CLI Version : 6.7.0 The Next.js config loads the parent .env using loadEnvConfig("..") , but it seems Prisma CLI does not load the parent .env when I run prisma db push. Should I duplicate DATABASE_URL inside ai-podcast-clipper-frontend/.env , or should I use something like dotenv-cli ? What is the cleanest way to make prisma db push read ../.env ? For a Supabase connection string, should [YOUR-PASSWORD] include the square brackets, or should I replace the whole placeholder? I am using: Prisma CLI: 6.7.0 Node.js: 20+ Windows PowerShell Supabase Postgres Next.js frontend I want to keep the root .env as the single source of truth if possible. If there is any issue with my Supabase connection, I tried using both Direct Connection and Session Pooler connection. The associated repository link is : https://github.com/LUNARTECH-X/DARK-PHOENIX
votes_count
0
comments_count
0
created_at_on_source
2026-05-23T12:01:00.000Z
topics
postgresqlnext.jsprismasupabase.env
media / source-specific data
{
  "stackoverflow": {
    "score": 0,
    "view_count": 78,
    "is_answered": false,
    "top_answers": [],
    "answer_count": 0,
    "accepted_answer_id": null,
    "last_activity_date": 1779537660
  }
}
raw_payload
{
  "stats": {
    "score": 0,
    "view_count": 78,
    "is_answered": false,
    "answer_count": 0,
    "creation_date": 1779537660,
    "last_edit_date": null,
    "accepted_answer_id": null,
    "last_activity_date": 1779537660
  },
  "api_wrapper": {
    "backoff": null,
    "has_more": true,
    "page_size": 8,
    "quota_max": 300,
    "quota_remaining": 200
  },
  "question_id": 79945585,
  "answer_fetch": {
    "has_more": false,
    "answers_fetched": 0,
    "answer_page_size": 3
  },
  "snapshot_version": "stackoverflow_question_v1"
}
source_raw_snapshot
{
  "id": "e4dd3a69-ba00-443f-9a16-32d0330e8664",
  "daily_ranking_item_id": "1ff729e7-9ca9-4c53-802a-8e97def0df70",
  "source": "stackoverflow",
  "external_id": "79945585",
  "fetched_at": "2026-05-27T22:01:45.075Z",
  "question_raw": {
    "body": "<p>I am working on a NEXT.js project that uses Prisma and Supabase Postgres.My project structure is:</p>\n<pre><code>Directory structure:\n└── lunartech-x-dark-phoenix/\n    ├── ai-podcast-clipper-backend/\n    │   ├── requirements.txt\n    │   ├── ytdownload.py\n    │   └── asd/\n    │       └── model/\n    │           └── faceDetector/\n    │               ├── README.md\n    │               └── __init__.py\n    └── ai-podcast-clipper-frontend/\n        ├── add-credits.js\n        ├── components.json\n        ├── next.config.js\n        ├── postcss.config.js\n        ├── prettier.config.js\n        ├── tsconfig.json\n        └── src/\n            ├── app/\n            │   ├── layout.tsx\n            │   ├── api/\n            │   │   ├── auth/\n            │   │   │   └── [...nextauth]/\n            │   │   │       └── route.ts\n            │   │   └── inngest/\n            │   │       └── route.ts\n            │   ├── dashboard/\n            │   │   ├── layout.tsx\n            │   │   └── loading.tsx\n            │   ├── login/\n            │   │   └── page.tsx\n            │   └── signup/\n            │       └── page.tsx\n            ├── components/\n            │   └── ui/\n            │       ├── input.tsx\n            │       ├── label.tsx\n            │       └── sonner.tsx\n            ├── inngest/\n            │   └── client.ts\n            ├── lib/\n            │   ├── auth.ts\n            │   └── utils.ts\n            ├── schemas/\n            │   └── auth.ts\n            └── server/\n                ├── db.ts\n                └── auth/\n                    └── index.ts\n</code></pre>\n<p>The root <code>.env</code> file is supposed to be the single source of environment variables for the whole project.<br />\nIn <code>.env</code>, I have:</p>\n<pre><code>DATABASE_URL=&quot;postgresql://postgres.PROJECT_REF:MY_PASSWORD@aws-1-ap-southeast-2.pooler.supabase.com:5432/postgres&quot;\n</code></pre>\n<p>My prisma schema has:</p>\n<pre><code>datasource db {\n  provider = &quot;postgresql&quot;\n  url      = env(&quot;DATABASE_URL&quot;)\n}\n</code></pre>\n<p>When I run this command from the frontend folder:</p>\n<pre><code>cd ai-podcast-clipper-frontend\nnpm run db:push\n</code></pre>\n<p>The script runs:</p>\n<pre><code>prisma db push\n</code></pre>\n<p>But I get this error:</p>\n<pre><code>PS E:\\LunarTechTakeHomeAssignment(DarkPhoenix)\\DARK-PHOENIX\\ai-podcast-clipper-frontend&gt; npm run db:push\n\n&gt; ai-podcast-clipper-frontend@0.1.0 db:push\n&gt; prisma db push\n\nPrisma schema loaded from prisma\\schema.prisma\nError: Prisma schema validation - (get-config wasm)\nError code: P1012\nerror: Environment variable not found: DATABASE_URL.\n  --&gt;  prisma\\schema.prisma:14\n   |\n13 |     // https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string\n14 |     url      = env(&quot;DATABASE_URL&quot;)\n   |\n\nValidation Error Count: 1\n[Context: getConfig]\n\nPrisma CLI Version : 6.7.0\n</code></pre>\n<p>The Next.js config loads the parent <code>.env</code> using <code>loadEnvConfig(&quot;..&quot;)</code>, but it seems Prisma CLI does not load the parent <code>.env</code> when I run <code>prisma db push.</code></p>\n<p>Should I duplicate <code>DATABASE_URL</code> inside <code>ai-podcast-clipper-frontend/.env</code>, or should I use something like <code>dotenv-cli</code>?</p>\n<p>What is the cleanest way to make <code>prisma db push</code> read <code>../.env</code>?</p>\n<p>For a Supabase connection string, should <code>[YOUR-PASSWORD]</code> include the square brackets, or should I replace the whole placeholder?</p>\n<p>I am using:</p>\n<pre><code>Prisma CLI: 6.7.0\nNode.js: 20+\nWindows PowerShell\nSupabase Postgres\nNext.js frontend\n</code></pre>\n<p>I want to keep the root <code>.env</code> as the single source of truth if possible.</p>\n<p>If there is any issue with my Supabase connection, I tried using both Direct Connection and Session Pooler connection.</p>\n<p>The associated repository link is : <a href=\"https://github.com/LUNARTECH-X/DARK-PHOENIX\" rel=\"nofollow noreferrer\">https://github.com/LUNARTECH-X/DARK-PHOENIX</a></p>\n",
    "link": "https://stackoverflow.com/questions/79945585/prisma-db-push-cannot-find-database-url-when-env-is-in-parent-directory",
    "tags": [
      "postgresql",
      "next.js",
      "prisma",
      "supabase",
      ".env"
    ],
    "owner": {
      "link": "https://stackoverflow.com/users/9348836/bibashmanjusubedi",
      "user_id": 9348836,
      "user_type": "registered",
      "account_id": 12929301,
      "reputation": 1375,
      "display_name": "bibashmanjusubedi",
      "profile_image": "https://i.sstatic.net/NnkF5.jpg?s=256"
    },
    "score": 0,
    "title": "Prisma db push cannot find DATABASE_URL when .env is in parent directory",
    "view_count": 78,
    "is_answered": false,
    "question_id": 79945585,
    "answer_count": 0,
    "creation_date": 1779537660,
    "content_license": "CC BY-SA 4.0",
    "last_activity_date": 1779537660
  },
  "answers_raw": [],
  "tags_raw": [
    "postgresql",
    "next.js",
    "prisma",
    "supabase",
    ".env"
  ],
  "stats_raw": {
    "score": 0,
    "view_count": 78,
    "is_answered": false,
    "answer_count": 0,
    "creation_date": 1779537660,
    "last_edit_date": null,
    "accepted_answer_id": null,
    "last_activity_date": 1779537660
  },
  "selection_meta": {
    "site": "stackoverflow",
    "api_wrapper": {
      "backoff": null,
      "has_more": true,
      "page_size": 8,
      "quota_max": 300,
      "quota_remaining": 200
    },
    "answer_fetch": {
      "backoff": null,
      "has_more": false,
      "answers_fetched": 0,
      "quota_remaining": 172,
      "answer_page_size": 3
    },
    "snapshot_version": "stackoverflow_question_v1",
    "selection_strategy": "tag_whitelist_unanswered_high_score_recent_active"
  },
  "created_at": "2026-05-27T22:01:45.591Z",
  "updated_at": "2026-05-27T22:01:45.591Z"
}