I'm using Prisma 6.13 in a project with NextJs and I want to implement the seed process using the new modern configuration approach prisma.config.ts
as recommended by Prisma in recent versions.
I'm no longer using package.json
to define the seed command. Previously, it was necessary to add:
"prisma": {
"seed": "tsx prisma/seed.ts"
}
Here's my current project structure:
- prisma/
- schema.prisma
- seed.ts
- db/
- migrations/
- lib/
- prisma.ts
- prisma.config.ts
My seed.ts
file:
import { categories } from "@/prisma/data/categories";
import { products } from "@/prisma/data/products";
import prisma from "@/lib/prisma";
async function main() {
try {
await prisma.category.createMany({ data: categories });
await prisma.product.createMany({ data: products });
} catch (e) {
console.error(e);
} finally {
await prisma.$disconnect();
}
}
main().catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});
My prisma.config.ts
, where I define the schema path, migrations path, and load environment variables:
import { defineConfig } from "prisma/config";
import path from "node:path";
process.loadEnvFile();
export default defineConfig({
schema: path.join("prisma", "schema.prisma"),
migrations: {
path: path.join("db", "migrations"),
},
});
When I run:
npx prisma db seed
It doesn't throw any errors, but the seed is not executed. No data is inserted into the database.
What’s the proper way to run seeds in Prisma 6+ with the new configuration?
Is there any official way to define the path to the seed.ts
file inside prisma.config.ts
?
The documentation doesn't clearly explain how to use prisma.config.ts
for the seeding process with Prisma 6+. It only covers the old setup through package.json
, and there's no clear guidance about whether this is officially supported or planned for Prisma 7.
in your prisma.config.ts
you need to add the seed
to your defineConfig
like so:
export default defineConfig({
schema: path.join("prisma", "schema.prisma"),
migrations: {
path: path.join("db", "migrations"),
seed: "tsx prisma/seed.ts"
}
});