node.js - PrismaClient 验证错误 : Invalid `prisma.user

我正在尝试使用 Next.js 和 Prisma 创建一个 API。我有两个模型用户和个人资料。 我想使用 postman 从 req.body 创建用户和配置文件字段。

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

我该如何解决这个问题?

最佳答案

解决这个问题

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

关于node.js - PrismaClient 验证错误 : Invalid `prisma.user.create()` invocation:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68246739/

相关文章:

c++ - std::reference_wrapper 和 T 之间的最佳可行重

android-studio - 在 Play Store Console 中更改草稿应用程序的应用

python - Pycharm调试Django项目(Dev分支)的问题

reactjs - 如何使可选的对等依赖项真正可选

javascript - 来自 "pages/[...slug].js"的 Next.js 路由不起

postgresql - psql:致命:用户 ""aws rds Postgresql 的 PAM

android - 如何公开 StateFlow 但启动和停止底层 Flow

java - 如何在@Async 方法中测试异常?

nestjs - 如何在 typeorm 中合并两个表?

javascript - 在开始下一个功能之前等待一个功能完成