next.js PrismaClientValidationError:无效的`prisma.user.create()`调用:

lo8azlld  于 2023-05-12  发布在  Mac
关注(0)|答案(2)|浏览(267)

我正在尝试使用Next.js和Prisma创建一个API。我有两个模型用户和个人资料。我想创建用户和配置文件字段也从请求。身体使用 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" });

URL命中后,我得到了一个错误。PrismaClientValidationError:无效的prisma.user.create()调用Data.profile中UserCreateInput类型的未知参数profile。你是说email吗可用参数:键入UserCreateInput
我该如何解决这个问题?

yzuktlbb

yzuktlbb1#

尝试Prisma迁移

npx prisma migrate

仅适用于开发中运行

npx prisma migrate dev

命名迁移

npx prisma migrate dev --name init
tktrz96b

tktrz96b2#

解决这个问题

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

相关问题