【发布时间】:2022-11-14 12:55:43
【问题描述】:
我有这两个型号
model School {
id Int @id @default(autoincrement())
name String?
center_no Int?
type String?
subjects SubjectPool[]
}
model SubjectPool {
id Int @id @default(autoincrement())
name String?
code String?
school School? @relation(fields: [school_id], references: [id])
school_id Int?
}
我正在尝试使用 seed.ts 文件中的此查询为数据库播种
await prisma.school.create({
data: {
...school,
subjects: {
create: [ math, english, geography]
}
},
include: {
subjects: true
}
})
但问题是我得到了这个错误:
Unknown arg `school_id` in data.subjects.create.1.school_id for type SubjectPoolUncheckedCreateWithoutSchoolInput. Did you mean `class_id`? Available args:
type SubjectPoolUncheckedCreateWithoutSchoolInput {
id?: Int
name?: String | Null
code?: String | Null
class_id?: Int | Null
}
似乎在我认为存在的主题池模型上找不到学校 ID 字段。
这是我在遇到此错误之前运行的命令序列:
dropdb dbname
createdb dbname
npx prisma db push / npx prisma migrate dev (if i have made a change to the model)
npx prisma db seed
我正在使用 postgres 数据库。完整的错误:
await prisma.school.create({
data: {
id: 1,
name: 'kansenshi secondary school',
center_no: 2783783,
type: 'gov',
province: 'copperbelt',
district: 'Ndola',
subjects: {
create: [
null,
{
id: 3,
name: 'English',
code: '234',
school_id: null,
~~~~~~~~~
class_id: null
},
null
]
}
},
include: {
subjects: true
}
})
Unknown arg `school_id` in data.subjects.create.1.school_id for type SubjectPoolUncheckedCreateWithoutSchoolInput. Did you mean `class_id`? Available args:
type SubjectPoolUncheckedCreateWithoutSchoolInput {
id?: Int
name?: String | Null
code?: String | Null
class_id?: Int | Null
schedule?: ClassScheduleUncheckedCreateNestedManyWithoutSubjectInput
}
【问题讨论】:
标签: node.js reactjs next.js graphql prisma