# My deployed Next.js app says DATABASE_URL is missing and I have no database yet. What do I need to do? `DATABASE_URL` is the environment variable that holds your database's connection string, and the deployed app can't find it because there is no database yet and your host has no value for it. A local `.env` file is usually kept out of Git, so the deployment doesn't have it. Create a Postgres database with any managed provider, copy its connection string, add it as `DATABASE_URL` in your host's environment settings for production (and for the build if your pages query the database while building), apply your schema to the new database, then redeploy, because many hosts pass new variables only to new deployments. With [Prisma Postgres](/docs/postgres), `npx create-db@latest` gives you a temporary database with no account in a few seconds, and the [Prisma Console](https://console.prisma.io) or the Vercel Marketplace integration gives you one that stays. By [Gregory Boch](https://github.com/gregory-boch-prisma) · 2026-10-19 · 8 min read · Updated 2026-10-30 Your app reads `process.env.DATABASE_URL` to find its database, and on the server it was deployed to, nothing sets that variable. Because you haven't created a database yet, there is no connection string to give it. To fix it, create a database, put its connection string into your host's environment settings, create your tables in the new database and deploy again. We make Prisma Postgres and Prisma Compute. The steps below work with any Postgres provider, host and database client. Every host behavior on this page links to that host's documentation, checked on October 19, 2026. ## What DATABASE_URL is and why the deploy can't find it `DATABASE_URL` is the conventional name for an environment variable that holds a PostgreSQL connection string such as `postgres://USER:PASSWORD@HOST:5432/DATABASE?sslmode=require`. Next.js doesn't define it. Your code, your ORM's config or the starter template you used reads `process.env.DATABASE_URL` and passes the value to the database client. Prisma ORM's [default config](/docs/orm/v7/reference/prisma-config-reference) uses that name, and so do many templates. On your machine, [Next.js loads `.env*` files](https://nextjs.org/docs/app/guides/environment-variables) from the project root into `process.env`. In a `create-next-app` project those files are in `.gitignore`, so a deploy from your Git repository doesn't include them. The host only knows the variables you set in its dashboard, CLI or config, and a template that expects a database can't get a value from anywhere until you create one. The message depends on what reads the variable: - **Prisma ORM 7:** `PrismaConfigEnvError: Cannot resolve environment variable: DATABASE_URL.`, after `Failed to load config file ...` in the log, from the `env()` helper in `prisma.config.ts`. Early Prisma ORM 7 releases print `Missing required environment variable: DATABASE_URL` instead. It appears during `prisma generate`, often in a `postinstall` script, even though generate doesn't connect to the database ([config reference](/docs/orm/v7/reference/prisma-config-reference)). - **Prisma ORM 6:** `Environment variable not found: DATABASE_URL.` from `env("DATABASE_URL")` in `schema.prisma` ([error reference](/docs/orm/v6/reference/error-reference)). - **Your own code or a template:** a check such as `throw new Error("DATABASE_URL is not set")`, or a connection error from the driver when it gets `undefined`. node-postgres, for example, then falls back to localhost and fails with `ECONNREFUSED` on port 5432. It can fail at two moments. During the build, any page that `next build` prerenders by querying the database needs the variable, and so does `prisma generate` with Prisma ORM 7 when `prisma.config.ts` uses `env("DATABASE_URL")`. At runtime, the first request to a route that queries the database needs it. ## How do I fix it? ### 1. Create a Postgres database Any managed PostgreSQL works. Pick the one that fits where your app runs: - **A provider through your host.** On Vercel, the old Vercel Postgres product is gone; Postgres now comes from [Marketplace integrations](https://vercel.com/docs/postgres) that create the database and add its variables to your project. - **A database on the same host.** On Railway, for example, a PostgreSQL service exposes `DATABASE_URL` and other variables that your app service [references](https://docs.railway.com/databases/postgresql). - **A separate Postgres provider.** Create the database in its dashboard and copy the connection string. For a Prisma Postgres database, see [Where do Prisma Postgres and Prisma Compute fit?](#where-do-prisma-postgres-and-prisma-compute-fit) below. ### 2. Copy the connection string Copy the string the provider gives you, with `sslmode=require` if it includes one. If the app then fails with an SSL or certificate error, see [how to fix SSL errors between Node and hosted Postgres](/postgres/ssl-connection-error). If the provider offers a pooled and a direct string, use the pooled one for the app on a serverless host and keep the direct one for migrations. For local runs, put the connection string of a separate development database in your local `.env`, so local work and schema experiments never write to production data: ```bash title=".env" DATABASE_URL="postgres://USER:PASSWORD@DEV_HOST:5432/DATABASE?sslmode=require" ``` Don't add a `NEXT_PUBLIC_` prefix. Next.js [inlines `NEXT_PUBLIC_` variables](https://nextjs.org/docs/app/guides/environment-variables#bundling-environment-variables-for-the-browser) into the JavaScript sent to the browser, which would publish your password. Server Components, Route Handlers and Server Actions can read `DATABASE_URL` without it. ### 3. Set DATABASE_URL on your host Add the variable in your host's settings for production. Where to set it, and when the running app picks it up: | Host | Where to set it | When it applies | | --- | --- | --- | | [Fly.io](https://fly.io/docs/apps/secrets/) | `fly secrets set DATABASE_URL=...` | Machines restart with the new secret. Secrets are not available while the Docker image builds; Fly documents build secrets for that | | [Netlify](https://docs.netlify.com/build/environment-variables/get-started/) | Project configuration, Environment variables, or `netlify env:set` | After the next build and deploy. Values set in `netlify.toml` reach the build but [not Functions](https://docs.netlify.com/build/environment-variables/overview/), which [run Next.js server rendering, Route Handlers and Server Actions](https://docs.netlify.com/build/frameworks/framework-setup-guides/nextjs/overview/) | | [Prisma Compute](/docs/compute/environment-variables) | `DATABASE_URL="postgres://..." npx prisma@latest project env add DATABASE_URL --role production` | On the next deploy | | [Railway](https://docs.railway.com/variables) | The app service's Variables tab, for example `DATABASE_URL=${{Postgres.DATABASE_URL}}` to reference a database service named Postgres | After you review and deploy the staged changes | | [Render](https://render.com/docs/configure-environment-variables) | The service's Environment page | When you pick a save option that deploys. "Save and deploy" reuses the existing build, so pick "Save, rebuild, and deploy" if the build reads the variable; "Save only" waits for the next deploy | | [Vercel](https://vercel.com/docs/environment-variables/managing-environment-variables) | The project's Environment Variables page, or `vercel env add DATABASE_URL production` | Only on new deployments, so redeploy | Hosts are listed alphabetically. On Vercel and Netlify, a variable can apply to some environments or deploy contexts and not others, so make sure production is selected. If you test preview deployments, set a preview value too, pointing at a separate test database rather than the production one, so previews can't read or change live records. A variable set for every environment gives previews the production value; [giving previews a separate database](/postgres/nextjs-preview-separate-database) covers the setup. ### 4. Make the variable available where it's read If the build fails, the variable has to exist during the build, not only at runtime. Railway passes variables to [both the build and the running service](https://docs.railway.com/variables), and Vercel lets code read them in the [Build Step and in Functions](https://vercel.com/docs/environment-variables). On other hosts, check the scope. You can also keep the database out of the build: - **Pages that query the database while prerendering.** Render them at request time instead. In the App Router, `await connection()` from `next/server` makes a page [read environment variables at runtime](https://nextjs.org/docs/app/guides/environment-variables#runtime-environment-variables). - **Prisma ORM 7's `prisma generate`.** Generate doesn't need a database. Replace `env("DATABASE_URL")` in `prisma.config.ts` with `process.env.DATABASE_URL`, as the [config reference](/docs/orm/v7/reference/prisma-config-reference) suggests, and `prisma generate` no longer depends on the variable. A build step that runs migrations still needs it. ### 5. Create your tables, then redeploy A new database is empty. Apply your schema before the app takes traffic, with your migration tool's production command pointed at the production database. Use the direct connection string if the provider gave you a pooled and a direct one, because migrations need a stable session that a pooler in transaction mode doesn't keep. For example, `DATABASE_URL="" npx prisma@7 migrate deploy` (Prisma ORM 7, with `prisma.config.ts` reading `DATABASE_URL`), `npx drizzle-kit migrate` or `npx knex migrate:latest` with the same variable set. [Running database migrations safely in production](/postgres/production-database-migrations) covers each tool and how to make this a step in every deploy. Then deploy again: push a commit, run your host's redeploy command (`vercel redeploy ` on Vercel), or use the redeploy button in the dashboard. Open a page that reads from the database and check the function or server logs if it fails. A message that changes from "missing" to an authentication or `relation does not exist` error means the variable now arrives and the next problem is the credentials or the schema. ## If DATABASE_URL is still missing - **The variable is set but still missing.** Compare the exact name your code reads with the name on the host. Integrations often set several names: the Prisma Postgres integration on Vercel sets `DATABASE_URL`, `POSTGRES_URL`, `PRISMA_DATABASE_URL` and `DATABASE_URL_POOLED`, and other integrations choose their own names, so check what was added. Also check the environment (Production versus Preview) and that you redeployed after adding it. - **It's `undefined` in the browser.** Code in a Client Component runs in the browser, where server variables don't exist. Query the database in a Server Component, Route Handler or Server Action and pass the data down. - **Your app lives in a subfolder or a monorepo.** Next.js loads `.env` files from the project root, not from `src/`. On the host, set the variable on the project or service that builds the Next.js app. To catch this before a deploy, commit a `.env.example` that lists `DATABASE_URL` with a placeholder value, and have your database module throw a clear error at startup when the variable is empty, so the log names the missing variable instead of a driver error. ## Where do Prisma Postgres and Prisma Compute fit? [Prisma Postgres](/docs/postgres) is managed PostgreSQL 17 with a connection pooler for every database. Your app sees a regular connection string, so any PostgreSQL client works and Prisma ORM is optional. There are three ways to get one: - **No account, a few seconds:** `npx create-db@latest` (Node.js 20.5 or newer) prints a connection string and a claim URL. `npx create-db@latest --env .env` writes `DATABASE_URL` and `CLAIM_URL` to `.env` instead. If the file exists, it appends both lines without removing an old `DATABASE_URL`, such as a template's placeholder, so delete that line yourself. The database is deleted after 24 hours unless you claim it, and claiming it, which is free, needs a Prisma account. See [create-db](/docs/postgres/npx-create-db). - **A database that stays:** create a project and a database in the [Prisma Console](https://console.prisma.io), then click **Connect to your database** to generate the pooled and direct strings. From a terminal, `npx prisma@latest auth login` signs you in, `npx prisma@latest project create ` creates a project and links the directory to it, and `npx prisma@latest postgres create ` creates a database in that project and [prints its connection URL once](/docs/cli/postgres). - **On Vercel:** install the [Prisma Postgres integration](/docs/guides/postgres/vercel) from the Vercel Marketplace, create a database from the Storage tab and connect it to your project. The integration sets `DATABASE_URL` to the direct connection string and `DATABASE_URL_POOLED` to the pooled one on the environments you choose. Before production traffic, point your app's database client at `DATABASE_URL_POOLED`, keep `DATABASE_URL` for migrations and admin tools, and redeploy, as the [Vercel guide](/docs/guides/postgres/vercel#use-the-pooled-connection-string-for-application-traffic) describes. On some older databases `PRISMA_DATABASE_URL` holds a different URL, so don't use it for either. If a database created before October 29, 2026 has no `DATABASE_URL_POOLED`, add the pooled string yourself first. Direct connections are capped at 10 on the Free and Starter plans, and 5 of those are reserved for platform operations. If you deploy the app itself on [Prisma Compute](/docs/compute), it hosts Next.js apps built with `output: "standalone"`, and the database can live in the same project. A database declared in your app's module is created when you deploy and its connection is injected into the app, so you don't set `DATABASE_URL` by hand. If you keep `DATABASE_URL`, set it with `npx prisma@latest project env add` and deploy again. The command takes the value from your shell, not from `.env`, so put it in front of the command: `DATABASE_URL="postgres://..." npx prisma@latest project env add DATABASE_URL --role production`. In a project with Prisma ORM 7 installed, plain `npx prisma` runs that version, which has no `project` command. Pages that read runtime configuration need `export const dynamic = "force-dynamic"` ([Compute FAQ](/docs/compute/faq)). Know the limits before you pick it: - The Free plan has no backups, and Prisma Postgres has no point-in-time recovery yet; it is coming in November 2026. Paid plans take daily snapshots on days with database activity. - Prisma Compute runs each app in one region and is not a CDN. If a globally cached frontend matters most, keep the Next.js app on Vercel and use Prisma Postgres as its database. - Prisma Compute does not run WebSocket servers today; support is planned for early 2027. [The Free plan](/postgres/free-postgresql-hosting) includes 200,000 operations a month and 2 GB of Prisma Postgres storage, with no credit card. See [pricing](/pricing) for the paid plans. ## Frequently asked questions ### Can I commit my .env file so the host gets DATABASE_URL? No. The connection string contains the database password, and anyone who can read the repository could then read and change your data. Next.js's `create-next-app` adds `.env` files to `.gitignore` for that reason. Set the value in your host's environment settings instead, and keep a copy in a password manager or secret store. ### Why does the build still say DATABASE_URL is missing after I added it? Check four things. The variable must be set for the environment you deployed (Production and Preview are separate on Vercel), and for the build if your host scopes variables (on Netlify, a variable scoped to Functions only isn't available to the build). The deployment must be new, because Vercel and Netlify apply changed variables only to new deploys. And with Prisma ORM 7, `env("DATABASE_URL")` in `prisma.config.ts` throws during `prisma generate` even though generate doesn't connect; the [Prisma docs](/docs/orm/v7/reference/prisma-config-reference) suggest `process.env.DATABASE_URL` when the variable may be absent. ### Should DATABASE_URL be the pooled or the direct connection string? On serverless hosts such as Vercel or Netlify, point the app at a pooled connection string, because every function instance opens its own connection. Run migrations over the direct string. With Prisma Postgres, the pooled host is `pooled.db.prisma.io` and the direct host is `db.prisma.io`; many apps keep the pooled string in `DATABASE_URL` and the direct one in a second variable such as `DIRECT_URL`. ### Can I use a database from npx create-db for my deployed app? For a test deploy, yes: it is a regular Prisma Postgres database with a standard connection string. It is deleted after 24 hours unless you claim it, so claim it with a free Prisma account before real users depend on it, or create the production database in the Prisma Console instead. The Free plan has no backups, so move to a paid plan before the data matters. ## Get a connection string in a few seconds Run `npx create-db@latest` for a Prisma Postgres database with no account, set it as DATABASE_URL on your host, and claim it to keep it. [Create a database](/docs/postgres/npx-create-db) ## Related guides - [Run database migrations safely in production](/postgres/production-database-migrations) - [API key works locally but is missing after deployment](/compute/missing-environment-variables-after-deploy) - [Migration step can't reach the database during a deploy](/postgres/migration-cannot-reach-database) - [Connecting to your Prisma Postgres database](/docs/postgres/database/connecting-to-your-database) - [create-db: a Postgres database without an account](/docs/postgres/npx-create-db) - [Prisma Postgres on the Vercel Marketplace](/docs/guides/postgres/vercel) - [Connection string works locally but the deployed app times out](/postgres/connection-timeout-after-deploy)