prisma:为什么我不能将 "null" 设置为可为空的列的默认值?

prisma: Why can't I set "null" as default value for nullable columns?

model Comment {
  id        Int        @id @default(autoincrement())
  reply     Comment?   @relation(fields: [replyId], references: [id], onDelete: SetNull)
  replyId   Int?       @default(null)
  comment   String
}

此处 replyreplyId 都可以为空,但是当我尝试迁移时出现此错误:

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)
   |

谁能解释一下这个问题?

您真的不需要为可选字段指定空默认值。如果您不指定 Comment 关系或明确提供记录的 replyId 值,则 replyId 的值自动为空。对于不充当外键的可选字段也是如此。

因此,您想要的行为会自动出现,无需定义 @default(null)