skip to content

After a Prisma 6 project moves to Prisma 7, its schema's datasource url and output-less generator block fail; what must change in those two blocks?

level: seniorimportance: must knowfreq 48%

answer

  1. two blocks above the models
  2. the URL left the schema file
  3. prisma-client needs a destination
  4. imports follow the output path

basics

~20 s

In Prisma 7 the datasource block keeps only provider and its options; url, directUrl and shadowDatabaseUrl move to prisma.config.ts. The generator becomes provider = "prisma-client" with a required output path, and imports switch from @prisma/client to that generated folder.

solid answer

~50 s

Prisma 7 rejects a `url` inside `datasource` with validation error `P1012`: "The datasource property `url` is no longer supported in schema files." The block keeps `provider` plus optional `relationMode`, `schemas` and `extensions`, and the CLI's connection URL moves to `prisma.config.ts`, while the running client gets its connection through a driver adapter. The generator should become `provider = "prisma-client"`, the default generator in Prisma 7, and it **requires** `output`; without it `prisma generate` stops with "An output path is required for the `prisma-client` generator." The path is relative to the schema file's folder, and application code then imports from it, for example `./generated/prisma/client`, instead of `@prisma/client`. The old `prisma-client-js` generator is deprecated but still accepted by Prisma 7.10.0, generating into `node_modules/.prisma/client`, so treat keeping it as a stopgap. Note too that `prisma migrate dev` no longer runs `generate` for you.

code

prisma · 8 lines
prisma
datasource db {
  provider = "postgresql"
}

generator client {
  provider = "prisma-client"
  output   = "../src/generated/prisma"
}

go deeper

for a junior

Recall the Prisma 7 shape: the datasource has a provider but no url, and the generator is prisma-client with an output folder you import PrismaClient from.

for a middle

Explain why each old line fails: url is a P1012 error, prisma-client requires output, and imports follow the generated path rather than @prisma/client.

for a senior

Lead an upgrade end to end: move URLs to the config file, regenerate with the new provider, fix imports, and make the build run prisma generate since migrate dev no longer does.

for a principal

Decide how far to take the upgrade in one step, prisma-client-js as a stopgap or the full move to prisma-client, and whether generated code is committed or built in CI.

## Two blocks that changed meaning in Prisma 7 Above its models, every Prisma schema carries two configuration blocks: - the **`datasource` block**, which says which database connector the schema targets; - one or more **`generator` blocks**, each saying what `prisma generate` should produce from the schema. In Prisma 6 and earlier, a typical schema looked like this: ```prisma datasource db { provider = "postgresql" url = env("DATABASE_URL") } generator client { provider = "prisma-client-js" } ``` Prisma 7 changed what both blocks may hold. Run against a 7.x CLI, that schema fails in two places. ## The datasource block: connector only In Prisma 7 the datasource block describes **which kind of database** the schema is written for, not **where it is**. Its fields are: | Field | Required | Purpose | | --- | --- | --- | | `provider` | yes | `postgresql`, `mysql`, `sqlite`, `sqlserver`, `cockroachdb` or `mongodb` | | `relationMode` | no | whether relations are enforced by foreign keys or emulated by Prisma | | `schemas` | no | the database schemas to include, for multi-schema setups | | `extensions` | no | PostgreSQL extensions to declare | Connection URLs are gone from the schema. Prisma 7.10.0 treats a leftover `url` as a validation error, not a warning: ```plaintext Error code: P1012 error: The datasource property `url` is no longer supported in schema files. Move connection URLs for Migrate to `prisma.config.ts` ... ``` `directUrl` and `shadowDatabaseUrl` fail the same way. The URL the CLI uses for migrations now lives under `datasource.url` in `prisma.config.ts`, and the application connects through a driver adapter passed to the `PrismaClient` constructor; both of those belong to Prisma's runtime configuration and are covered with connection and deployment. One upgrade detail follows from this: if `directUrl` used to point migrations past a connection pooler, that direct URL is now the value the config file's `url` should hold. ## The generator block: `prisma-client` with an `output` Prisma 7's default generator is `prisma-client`. Unlike the old `prisma-client-js`, it generates plain TypeScript into a folder of your project instead of into `node_modules`, so it needs to be told where: ```prisma generator client { provider = "prisma-client" output = "../src/generated/prisma" } ``` Key facts about it: 1. **`output` is required.** Without it, `prisma generate` stops with "An output path is required for the `prisma-client` generator." The path is resolved relative to the schema file's directory. 2. **Imports change.** Application code imports from the generated folder: `import { PrismaClient } from "./generated/prisma/client"` (adjusted for the importing file's location). Enums can be imported alone from `./generated/prisma/enums`, and `./generated/prisma/browser` exposes types and enums for front-end code without a `PrismaClient`. 3. **Optional fields** tune the output: `runtime` (default `nodejs`; also `deno`, `bun`, `workerd`, `vercel-edge`, `react-native`), `moduleFormat` (`esm` or `cjs`, inferred when omitted), `generatedFileExtension` and `importFileExtension`. 4. **No `.env` loading at runtime.** The generated client does not read `.env` files itself; load them with a library or set the variables in the environment. 5. **No automatic regeneration.** In Prisma 7, `prisma migrate dev` and `prisma db push` no longer run `prisma generate`, so a build or script must run it explicitly. The old `prisma-client-js` provider is **deprecated**, not yet removed: Prisma 7.10.0 still accepts it and generates into `node_modules/.prisma/client`, behind the `@prisma/client` import. The upgrade guide says it will be removed in a future release, so keeping it buys time, not a destination. ## An upgrade checklist for the schema file - Delete `url`, `directUrl` and `shadowDatabaseUrl` from `datasource`, and move the values into `prisma.config.ts`. - Change `provider = "prisma-client-js"` to `provider = "prisma-client"` and add `output`. - Leave `binaryTargets` behind: it is a field of the deprecated `prisma-client-js` generator, not of `prisma-client`. - Run `prisma generate`, then replace every `@prisma/client` import with the generated path. - Decide whether the generated folder is committed or ignored, and make sure the build runs `prisma generate` either way. Read in isolation, each step is small; missed together, they produce the classic upgrade failure where the schema validates on one machine and the build breaks on another.

  • Why does a Prisma 7 build fail with stale types after someone ran prisma migrate dev?
    In Prisma 7, `migrate dev` and `db push` no longer run `prisma generate`. The database changed, but the generated client in the `output` folder still reflects the old schema until `prisma generate` runs. Add it to the build and to the local workflow explicitly.
  • Can a Prisma 7 project keep the prisma-client-js generator for now?
    Yes, as a stopgap. Prisma 7.10.0 still accepts `prisma-client-js` and generates into `node_modules/.prisma/client`, so `@prisma/client` imports keep working. It is deprecated and the upgrade guide says it will be removed, so plan the move to `prisma-client` with an `output` path.
  • In Prisma 7, which path is the generator's output relative to?
    The directory that contains the schema file. With `prisma/schema.prisma` and `output = "../src/generated/prisma"`, the client lands in `src/generated/prisma`. Importing code then uses a path relative to its own file, such as `./generated/prisma/client` from `src/index.ts`.

  • In Prisma 7, url in the datasource block is only a deprecation warning.
  • The prisma-client generator writes into node_modules when output is omitted.
  • After the upgrade, PrismaClient is still imported from @prisma/client with prisma-client.
  • prisma migrate dev still regenerates the client in Prisma 7.
  • The output path is resolved from the project root, not the schema folder.

Assumes Prisma ORM 7; Prisma 6 kept url in the datasource block and defaulted to prisma-client-js generating into node_modules.