PrismaP
Prisma6mo ago
4 replies
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"
  },


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)
    })


What is the issue?
image.png
Was this page helpful?