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

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

Here both reply and replyId are nullable, but when I try to migrate I get this error:

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

Can anyone explain the problem?

1 Answers

You don't really need to specify a null default value for an optional field. If you don't specify Comment relation or explicitly provide the replyId value for a record, then the value of replyId is automatically null. This is true for optional fields that are not acting as foreign keys as well.

So, the behavior you want would be there automatically, there's no need to define @default(null).

Related