Prisma 7: datasource url No Longer Supported (Fix)

Prisma 7 moved the database URL out of schema.prisma. Put it in prisma.config.ts, load .env with dotenv, and pass a driver adapter to PrismaClient.
I upgraded the API behind this site from Prisma 6 to Prisma 7 (it runs 7.9 now), and the upgrade broke in three places, one after another. First the schema stopped validating. Then the client refused to start. Then DATABASE_URL was suddenly undefined even though the .env file hadn't changed. Each error tells you about one problem and stays quiet about the next one, so here is the whole list in the order you'll hit it.
The error
You run prisma generate, prisma migrate dev or just start your editor, and get this:
error: The datasource property `url` is no longer supported in schema files. Move connection URLs for Migrate to `prisma.config.ts` and pass either `adapter` for a direct database connection or `accelerateUrl` for Accelerate to the `PrismaClient` constructor.
The schema that triggers it is the one every Prisma project had for years:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
In Prisma 7, url, directUrl and shadowDatabaseUrl don't belong in the schema anymore. The CLI reads them from prisma.config.ts, and the client at runtime gets its connection from a driver adapter.
Key takeaways
- Delete
urlfrom thedatasourceblock. Keepprovider. - Create
prisma.config.tsnext topackage.jsonand put the URL there. - Prisma 7 doesn't load
.envfor you. Addimport "dotenv/config"at the top of the config file. - The client needs a driver adapter now (
@prisma/adapter-pgfor PostgreSQL), or it throws a second error at startup. migrate devno longer runsgenerateor the seed. Run them yourself in scripts and CI.
Step 1: Move the URL into prisma.config.ts
Strip the schema down to the provider:
datasource db {
provider = "postgresql"
}
Then create prisma.config.ts in the project root. This is the exact file our API runs in production:
import "dotenv/config";
import { defineConfig } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: process.env.DATABASE_URL!,
},
});
You can also write url: env("DATABASE_URL") with env imported from prisma/config. The difference matters in CI. env() throws PrismaConfigEnvError: Missing required environment variable: DATABASE_URL if the variable is missing, which breaks a build step that only runs prisma generate for types. process.env just passes undefined and lets generate continue. Since 7.2, prisma generate doesn't need a database URL at all, so I use process.env and keep CI simple.
If you used directUrl for a pooler like PgBouncer or Supabase, the URL the CLI should use for migrations is the direct one. Put that in datasource.url in the config, and give the pooled URL to the adapter in your app code.
Step 2: Load your .env file yourself
This one cost me the most time. Prisma 6 quietly loaded .env for both the CLI and the client. Prisma 7 loads nothing. If you forget the dotenv/config import, the CLI fails with a missing variable, and if your app didn't load .env on its own (because Prisma always did it), your app now connects with an undefined URL.
npm install dotenv
NestJS with @nestjs/config, Next.js and anything run through node --env-file=.env already load the file for the app, so only the config file needs the import. Plain Express or a script run with tsx needs it at the entry point too.
Step 3: Give PrismaClient a driver adapter
Fix the schema, start the app, and you get the next error:
PrismaClientConstructorValidationError: Using engine type "client" requires either "adapter" or "accelerateUrl" to be provided to PrismaClient constructor.
Prisma 7 dropped the Rust query engine. The client is TypeScript now and talks to the database through a normal Node driver. For PostgreSQL that's pg:
npm install @prisma/adapter-pg pg
import { PrismaClient } from "./generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
export const prisma = new PrismaClient({ adapter });
MySQL and MariaDB use @prisma/adapter-mariadb, SQLite uses @prisma/adapter-better-sqlite3. Setting engineType = "library" in the generator to get the old engine back doesn't work in 7.x, so don't spend time on it.
In NestJS, the usual PrismaService extends PrismaClient pattern still works. Pass the adapter through super():
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
constructor() {
super({ adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL }) });
}
async onModuleInit() {
await this.$connect();
}
}
Step 4: Check the generator block
New projects get provider = "prisma-client", which needs an output path and changes the import:
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
Then you import from ./generated/prisma/client, not @prisma/client. Add the folder to .gitignore and run prisma generate in your build. If you switch the provider and forget to update imports, you'll see "Cannot find module '.prisma/client/default'" or types that are all any.
The old prisma-client-js provider still generates on 7.x. Our API still uses it while running the pg adapter, so you don't have to move everything in one go. Get the app booting first, then switch the generator in its own commit.
Other things that changed quietly
prisma migrate devandprisma db pushno longer runprisma generate. Stale types after a migration mean you forgot this.- Seeding is no longer automatic after
migrate reset. Runprisma db seedyourself. The--skip-generateand--skip-seedflags are gone, so remove them from scripts. - The pool is now the
pgpool. Its default is 10 connections per process and no connection timeout (Prisma 6 used 5 seconds). If you run several pm2 instances, count them. I explain the math in my "too many clients already" fix. - Invalid SSL certificates are rejected now. A managed database with a self-signed cert that "worked fine" on Prisma 6 fails with a certificate error on 7. Give the adapter the CA file instead of turning verification off.
$use()middleware is removed. Move that logic to a client extension with$extends.- Prisma 7 needs Node 20.19 or newer and TypeScript 5.4 or newer.
A quick checklist before you deploy
npx prisma validate # schema is valid without url npx prisma generate # client builds npx prisma migrate status # CLI can reach the DB through prisma.config.ts npm run build && npm start # app connects through the adapter
On the server, make sure prisma.config.ts is actually copied into the release. A Dockerfile that only copies prisma/ and dist/ leaves it behind, and prisma migrate deploy in the container then fails with the same "url is no longer supported" message, because it can't find a URL anywhere. Copy prisma.config.ts and keep dotenv in dependencies, not devDependencies.
Frequently asked questions
Can I keep the url in schema.prisma on Prisma 7?
No. Prisma 7 rejects the schema with this error. Either move the URL to prisma.config.ts or stay on Prisma 6 until you have time for the upgrade. Prisma 6 still works fine.
Why is DATABASE_URL undefined after upgrading to Prisma 7?
Prisma 7 stopped loading .env automatically. Add import "dotenv/config" at the top of prisma.config.ts, and load the file in your app's entry point if your framework doesn't already.
Where does directUrl go in Prisma 7?
The CLI uses datasource.url in prisma.config.ts, so put your direct (non-pooled) URL there for migrations. Your app passes the pooled URL to the driver adapter.
Do I need a driver adapter in Prisma 7?
Yes, unless you use Prisma Accelerate. Without one, new PrismaClient() throws "Using engine type client requires either adapter or accelerateUrl".
Does prisma migrate deploy still work in Docker?
Yes, as long as the image contains prisma.config.ts, the prisma folder and dotenv, and the container has DATABASE_URL set.
Stuck halfway through a Prisma upgrade?
I've moved production NestJS and Next.js apps to Prisma 7 with the pg adapter, including Docker and CI changes. Book my bug fix service for React, Next.js and Node.js apps, see my web development services, or contact me with the error and your prisma.config.ts.
Written by
MD Rakibul Islam Rakib
Full-stack developer, DevOps engineer and Linux system administrator with 5+ years of production experience. I deploy, harden and fix servers and web apps for clients worldwide, and everything in this article runs on real servers I manage, including this site.
- prisma 7 datasource url
- prisma.config.ts
- prisma 7 upgrade
- prisma adapter-pg
- prisma 7 dotenv


