如果字段未设置值,prisma postgresql 无法设置未定义

prisma postgresql cant set undefined if field not set value

例子 架构

taxAmount!: Decimal | null;

和插入数据库的示例代码

 prisma.taxAmount = model.taxAmount ? parseFloat(model.taxAmount) : undefined;

和这个错误

Type 'Decimal | 'undefined' | null' is not assignable to type 'Decimal | null'.

类型 'undefined' 不可分配给类型 'Decimal | null'.ts(2322) (属性) DeliveryDetailsPrisma.taxAmount: 十进制 |空

如何解决?

您确定不能分配 null 而不是 undefined 吗? taxAmount 字段似乎需要 Decimalnull,而不是 undefined。此外,Null and undefined have separate meanings 在 Prisma 的上下文中。

如果您改为尝试以下操作,它应该可以正常工作。

prisma.taxAmount = model.taxAmount ? parseFloat(model.taxAmount) : null;