I am trying to update a record in prisma and it will not let me query the record with an update. I use the exact same where condition for both a findMany and the update but the update does not work. See error below for more details.
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()
}
})
}
Error in 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
Answers
The fix was to add a
@unique
to the paymentId in the schema. If you search by 1 column it needs to be a unique column in upload etc.Try this: