我正在尝试更新prisma中的记录,但它不允许我使用更新查询记录。我对findMany和更新使用了完全相同的where条件,但更新不起作用。有关详细信息,请参阅下面的错误。
const transaction = await prisma.coinTransaction.findMany({
where: {
paymentId: paymentIntent.id
},
select: {
paymentId: true
}
});
if (transaction.length > 1) {
console.log('Error not unique')
} else {
console.log('transaction: ', transaction[0])
await prisma.coinTransaction.update({
where: {
paymentId: paymentIntent.id
},
data: {
checkoutSessionCompleted: new Date()
}
})
}
vscode中的错误
Type '{ paymentId: any; }' is not assignable to type 'CoinTransactionWhereUniqueInput'.
Object literal may only specify known properties, and 'paymentId' does not exist in type 'CoinTransactionWhereUniqueInput'.ts(2322)
index.d.ts(11553, 5): The expected type comes from property 'where' which is declared here on type '{ select?: CoinTransactionSelect | null | undefined; include?: CoinTransactionInclude | null | undefined; data: (Without<CoinTransactionUpdateInput, CoinTransactionUncheckedUpdateInput> & CoinTransactionUncheckedUpdateInput) | (Without<...> & CoinTransactionUpdateInput); where: CoinTransactionWhereUniqueInput; }'
2条答案
按热度按时间xqkwcwgp1#
试试这个:
vltsax252#
修复方法是将
@unique
添加到架构中的paymentId。如果按1列搜索,则该列在上载等操作中必须是唯一的列。