PrismaClientValidationError: Invalid `prisma.user.create()` invocation:

Viewed 4062

I am trying to create an API using Next.js & Prisma. I have two model user & profile. I want to create user & also profile field from req.body using postman.

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id Int @id @default(autoincrement())
  name String
  email   String @unique
  password String
  profile Profile?
}

model Profile {
  id     Int     @default(autoincrement()) @id
  bio    String?
  user   User    @relation(fields: [userId], references: [id])
  userId Int   @unique
}

here my create function:

 //Create User
   let { name, email, password,  } = req.body;
    const createUser = await prisma.user.create({
      data: {
        name: name,
        email: email,
        password: user_password,
        profile: {
          create: { bio: 'Bsc' }
          },  
      }
    });
    res.status(201).json({ error: false, msg: "User Create Successfuly" });

After URL hit I got an error. PrismaClientValidationError: Invalid prisma.user.create() invocation Unknown arg profile in data.profile for type UserCreateInput. Did you mean email? Available args:type UserCreateInput

How can I solve this?

1 Answers

solve this issue

  let { name, email, password,  } = req.body;
//Create User
    const createUser = await prisma.user.create({
      data: {
        name: name,
        email: email,
        password: user_password,
        profile: {
          create: { bio: 'Learning Prisma' },
        },
         
      }
    });
    res.status(201).json({ error: false, msg: "User Create Successfuly" });
Related