Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 273
Al Imran Hossain Avatar asked May 18 '26 13:05

Al Imran Hossain


2 Answers

I have resolved this issue with the command

npx prisma generate
like image 95
Amber khan Avatar answered May 20 '26 02:05

Amber khan


I had the same issue, stop the server from running first and try to : npx yarn-upgrade-all

yarn add @prisma/client

npx prisma migrate reset

like image 27
mohamed daadaa Avatar answered May 20 '26 02:05

mohamed daadaa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!