From c17d236f5b1ed3fe0ff75f76cbc209b2a7f91c36 Mon Sep 17 00:00:00 2001 From: yuki kageyama Date: Tue, 17 Feb 2026 13:10:32 +0900 Subject: [PATCH] docs(docs): update seeding example to require adapter in Prisma ORM v7 In Prisma ORM v7, PrismaClient must be initialized with a driver adapter. Without it, running `prisma db seed` throws PrismaClientInitializationError. - Add adapter initialization using @prisma/adapter-pg and pg Pool - Add pool.end() in success and error handlers to prevent process hanging - Update dev dependency install command to include adapter packages - Add info callout explaining the v7 requirement --- .../orm/prisma-migrate/workflows/seeding.mdx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx b/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx index 9365b5b436..d95b2bfa4f 100644 --- a/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx +++ b/apps/docs/content/docs/orm/prisma-migrate/workflows/seeding.mdx @@ -68,9 +68,20 @@ model Post { Create some new users and posts in your `prisma/seed.ts` file: +:::info[Prisma ORM v7 requirement] +In Prisma ORM v7, `PrismaClient` must be initialized with a driver adapter. The example below uses `@prisma/adapter-pg` with a PostgreSQL connection pool. +::: + ```js title="seed.ts" +import "dotenv/config"; +import { Pool } from "pg"; +import { PrismaPg } from "@prisma/adapter-pg"; import { PrismaClient } from "../prisma/generated/client"; -const prisma = new PrismaClient(); + +const connectionString = `${process.env.DATABASE_URL}`; +const pool = new Pool({ connectionString }); +const adapter = new PrismaPg(pool); +const prisma = new PrismaClient({ adapter }); async function main() { const alice = await prisma.user.upsert({ where: { email: "alice@prisma.io" }, @@ -114,18 +125,20 @@ async function main() { main() .then(async () => { await prisma.$disconnect(); + await pool.end(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); + await pool.end(); process.exit(1); }); ``` -- Add `typescript`, `tsx` and `@types/node` development dependencies: +- Add `typescript`, `tsx`, `@types/node`, `@prisma/adapter-pg`, `pg`, `@types/pg` and `dotenv` development dependencies: ```npm -npm install -D typescript tsx @types/node +npm install -D typescript tsx @types/node @prisma/adapter-pg pg @types/pg dotenv ``` - Add the `seed` field to your `prisma.config.ts` file: @@ -176,10 +189,12 @@ main() .then(rawSql) .then(async () => { await prisma.$disconnect(); + await pool.end(); }) .catch(async (e) => { console.error(e); await prisma.$disconnect(); + await pool.end(); process.exit(1); }); ```