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, npx create-db@latest gives you a temporary database with no account in a few seconds, and the Prisma Console or the Vercel Marketplace integration gives you one that stays.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 uses that name, and so do many templates.
On your machine, Next.js loads .env* files 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., afterFailed to load config file ...in the log, from theenv()helper inprisma.config.ts. Early Prisma ORM 7 releases printMissing required environment variable: DATABASE_URLinstead. It appears duringprisma generate, often in apostinstallscript, even though generate doesn't connect to the database (config reference). - Prisma ORM 6:
Environment variable not found: DATABASE_URL.fromenv("DATABASE_URL")inschema.prisma(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 getsundefined. node-postgres, for example, then falls back to localhost and fails withECONNREFUSEDon 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 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_URLand other variables that your app service references. - 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? 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. 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:
DATABASE_URL="postgres://USER:PASSWORD@DEV_HOST:5432/DATABASE?sslmode=require"Don't add a NEXT_PUBLIC_ prefix. Next.js inlines NEXT_PUBLIC_ variables 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 | 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 | 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, which run Next.js server rendering, Route Handlers and Server Actions |
| Prisma Compute | DATABASE_URL="postgres://..." npx prisma@latest project env add DATABASE_URL --role production | On the next deploy |
| Railway | 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 | 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 | 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 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, and Vercel lets code read them in the Build Step and in Functions. 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()fromnext/servermakes a page read environment variables at runtime. - Prisma ORM 7's
prisma generate. Generate doesn't need a database. Replaceenv("DATABASE_URL")inprisma.config.tswithprocess.env.DATABASE_URL, as the config reference suggests, andprisma generateno 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="<direct connection string>" 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 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 <deployment-url> 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_URLandDATABASE_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
undefinedin 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
.envfiles from the project root, not fromsrc/. 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 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 .envwritesDATABASE_URLandCLAIM_URLto.envinstead. If the file exists, it appends both lines without removing an oldDATABASE_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. - A database that stays: create a project and a database in the Prisma Console, then click Connect to your database to generate the pooled and direct strings. From a terminal,
npx prisma@latest auth loginsigns you in,npx prisma@latest project create <name>creates a project and links the directory to it, andnpx prisma@latest postgres create <name>creates a database in that project and prints its connection URL once. - On Vercel: install the Prisma Postgres integration from the Vercel Marketplace, create a database from the Storage tab and connect it to your project. The integration sets
DATABASE_URLto the direct connection string andDATABASE_URL_POOLEDto the pooled one on the environments you choose. Before production traffic, point your app's database client atDATABASE_URL_POOLED, keepDATABASE_URLfor migrations and admin tools, and redeploy, as the Vercel guide describes. On some older databasesPRISMA_DATABASE_URLholds a different URL, so don't use it for either. If a database created before October 29, 2026 has noDATABASE_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, 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).
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 includes 200,000 operations a month and 2 GB of Prisma Postgres storage, with no credit card. See pricing for the paid plans.
Frequently asked questions
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.env("DATABASE_URL") in prisma.config.ts throws during prisma generate even though generate doesn't connect; the Prisma docs suggest process.env.DATABASE_URL when the variable may be absent.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.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.
Related guides
- Run database migrations safely in production
- API key works locally but is missing after deployment
- Migration step can't reach the database during a deploy
- Connecting to your Prisma Postgres database
- create-db: a Postgres database without an account
- Prisma Postgres on the Vercel Marketplace
- Connection string works locally but the deployed app times out