Skip to content

Fix Prisma 7 datasource URL no longer supported in schema

fix

Prisma 7 rejects datasource url property in schema.prisma with error code P1012

prismadatabasemigrationtypescript
21 views

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 generator provider also changed from "prisma-client-js" to "prisma-client" in Prisma 7
  • Direct URLs for connection pooling (previously directUrl in the datasource block) also move to prisma.config.ts
  • The prisma init command in v7 generates prisma.config.ts automatically for new projects
  • If you use multiple schema files (prismaSchemaFolder preview feature), point the schema field to the directory
  • The earlyAccess flag is required during the Prisma 7 early access period and can be removed once Prisma 7 reaches stable
About this share
Contributormblode
Repositorymblode/shares
CreatedFeb 9, 2026
Environmentprisma 7.0+
View on GitHub