P
Prisma3w ago
dotEXE

Can't use npx prisma db seed

Hello, this is what I get from the command I installed ts-node and added in package.json:
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
This is the prisma/seed.ts
import { Prisma, PrismaClient } from "@/app/generated/prisma"

const prisma = new PrismaClient();

const initialPosts: Prisma.PostCreateInput[] = [
{
title: "First Post",
slug: "first-post",
content: "This is the content of the first post.",
author: {
connectOrCreate: {
where: { email: "abc@gmail.com" },
create: {
email: "abc@gmail.com",
hashedPassword: "$2b$10$EIXe5z1Z3a7f8Q9j6k5hOe",
}
}
}
}
];

async function main() {
console.log('Start seeding...');
for (const post of initialPosts) {
await prisma.post.create({ data: post });
}
console.log('Seeding finished.');
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
import { Prisma, PrismaClient } from "@/app/generated/prisma"

const prisma = new PrismaClient();

const initialPosts: Prisma.PostCreateInput[] = [
{
title: "First Post",
slug: "first-post",
content: "This is the content of the first post.",
author: {
connectOrCreate: {
where: { email: "abc@gmail.com" },
create: {
email: "abc@gmail.com",
hashedPassword: "$2b$10$EIXe5z1Z3a7f8Q9j6k5hOe",
}
}
}
}
];

async function main() {
console.log('Start seeding...');
for (const post of initialPosts) {
await prisma.post.create({ data: post });
}
console.log('Seeding finished.');
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
What is the issue?
No description
4 Replies
Prisma AI Help
Ahoy, knowledge seeker! I'm the Prisma AI Help Bot. Do you want a dev's response that might take a hot second, or an AI answer that's ready before your next coffee sip? Either way, your question is important to us.
Nurul
Nurul3w ago
What happens if you use tsx instead of ts-node? Does tsx prisma/seed.ts also fail?
Parwar Yassin
Parwar Yassin3w ago
mine is work with tsx "seed": "tsx prisma/seed.ts".
Nurul
Nurul2w ago
Glad to hear that! You can use tsx instead of ts-node 👍

Did you find this page helpful?