orm - prisma:为什么我不能将“null”设置为可空列的默认值?
问题描述
model Comment {
id Int @id @default(autoincrement())
reply Comment? @relation(fields: [replyId], references: [id], onDelete: SetNull)
replyId Int? @default(null)
comment String
}
这里两者reply
和replyId
都是可以为空的,但是当我尝试迁移时,我得到了这个错误:
error: Error parsing attribute "@default": Expected a numeric value, but received literal value "Null".
--> schema.prisma:70
|
69 | reply Comment? @relation(fields: [replyId], references: [id], onDelete: SetNull)
70 | replyId Int? @default(null)
|
谁能解释这个问题?
解决方案
您实际上不需要为可选字段指定 null 默认值。如果您不指定 Comment
关系或明确提供replyId
记录的值,则 的值replyId
自动为空。对于不充当外键的可选字段也是如此。
因此,您想要的行为会自动出现,无需定义@default(null)
.
推荐阅读
- jquery - 使用引导表期间的详细视图不起作用
- authentication - asp.Net core 2.2中的多种身份验证方法
- scala - 火花数据集的问题
- sass - 将参数列表传递给 sass mixin 并从中组合一个值
- java - 具有地图属性的实体的休眠查询
- hive - 如何处理 hive 中的嵌入式逗号?
- bash - 将变量设置为curl输出时退出bash脚本
- javascript - FancyBox - 使用 iframe 的箭头/导航
- windows-7 - ollydbg 中的入口点不是根据 PE 中的 ImageBase 值
- c# - 代码在 Visual Studio 中编译和运行,即使它具有未引用的类的名称