Problem
After upgrading to Prisma 7, running prisma generate or prisma migrate fails with a P1012 error because the url property inside datasource is no longer supported in schema files:
Error: Prisma schema validation - (P1012)
The datasource property 'url' is no longer supported in schema files.
Move connection URLs for Migrate to 'prisma.config.ts'.
--> schema.prisma:4
|
3 | datasource db {
4 | provider = "postgresql"
5 | url = env("DATABASE_URL")
| ^^^^^^^^^^^^^^^^^^^
6 | }
The schema that worked in Prisma 6 but now fails:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
}
Solution
Remove the url from schema.prisma and add a prisma.config.ts file at the project root:
Updated schema.prisma:
generator client {
provider = "prisma-client"
}
datasource db {
provider = "postgresql"
}
model User {
id Int @id @default(autoincrement())
email String @unique
}
New prisma.config.ts:
import path from "node:path";
import { defineConfig } from "prisma/config";
export default defineConfig({
earlyAccess: true,
schema: path.join(__dirname, "prisma", "schema.prisma"),
migrate: {
async url() {
return process.env.DATABASE_URL ?? "";
},
},
});
Why It Works
Prisma 7 adopts a TypeScript-first configuration model that separates the connection URL (a runtime concern) from the schema definition (a structural concern). The prisma.config.ts file lets you use dynamic logic, environment-specific branching, or secret managers to resolve the database URL at runtime. The Prisma CLI and Prisma Client both read from this config file, so prisma migrate, prisma generate, and runtime queries all use the same source of truth.
Context
- Prisma 7.0+ with the new TypeScript config system
- The
generatorprovider also changed from"prisma-client-js"to"prisma-client"in Prisma 7 - Direct URLs for connection pooling (previously
directUrlin the datasource block) also move toprisma.config.ts - The
prisma initcommand in v7 generatesprisma.config.tsautomatically for new projects - If you use multiple schema files (
prismaSchemaFolderpreview feature), point theschemafield to the directory - The
earlyAccessflag is required during the Prisma 7 early access period and can be removed once Prisma 7 reaches stable