Hi, hope you're doing well! I have created a seede...
# orm-help
m
Hi, hope you're doing well! I have created a seeder function but it seems like it's not working. Here is the code
Copy code
import faker from "faker";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

export async function seed() {
  const user = await prisma.user.create({
    data: {
      lastName: faker.name.lastName(),
      firstName: faker.name.firstName(),
    },
  });

  const post = await prisma.post.create({
    data: {
      userId: user.id,
      body: faker.lorem.slug(300),
    },
  });

  console.log({ post, user });
}
The information is not being logged and is not being saved to the database... Is there something wrong or am I doing something not correctly?
j
How are you triggering that? Windows?
๐Ÿ‘ 1
m
Is the
seed.js
file inside the
/prisma
directory? And youโ€™re using the
npx prisma db seed --preview-feature
command right?
๐Ÿ‘ 1
m
Sorry for the late reply but yeah @janpio Iโ€™m running Windows 10
Yup! @Mahmoud
j
(the pkg.json script part)
m
Thanks will definitely check it out! Have a good day ๐Ÿ™‚
๐Ÿ‘ 1
Still, seeding does not work even with the included script. My rows/columns are empty
Wait, I think it worked. After adding
seed();
call in the end of my file it worked
m
Hmm, this shouldnโ€™t be needed
m
Yeah
j
Actually, executing the main function is probably required to actually run the code, right @Mahmoud?
๐Ÿค” 1
m
Having an exported async function called
seed
should work. I tried it before https://www.prisma.io/docs/guides/database/seed-database#requirements-for-seeding-with-typescript-or-javascript
๐Ÿ‘ 1
prisma rainbow 1
@Michael Grigoryan do you mind writing your seed script this way like in this example and trying it? https://www.prisma.io/docs/guides/database/seed-database#seeding-your-database-with-typescript
m
Sure
Nice! It worked this time ๐Ÿ™‚
๐Ÿ‘ 2