Migrating and Using Prisma Client with Seed

  const { PrismaClient } = require('@prisma/client');

    const prisma = new PrismaClient();

    async function main() {
        const newUser = await prisma.user.create({
            data: {
                name: 'Alice',
                email: 'alice@example.com',
            },
        });
        console.log(newUser);
    }

    main().catch((e) => {
        throw e;
    }).finally(async () => {
        await prisma.$disconnect();
    });

After setting up your database and shadow database, use the Prisma Client to interact with your MySQL database. Below is an example of creating a new user record.

The Prisma PHP package by default includes a seed.ts file, which is located at prisma/seed.ts. This file serves as a template ready to set your data and execute to seed the database.

Execute npx prisma migrate dev after preparing all data to migrate or seed. This command automatically executes the seed if it is included in package.json: "prisma": {"seed": "tsx prisma/seed.ts"}.

To seed data into the database, execute: npx prisma db seed.