我正在尝试使用 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/