Nathaniel Babalola
02/01/2022, 12:32 PMForeign key constraint failed on the field: transactions_senderId_fkey (index)
When I try to insert.
And I have no idea why. There shouldn't be on that field.
Here's my model
model user {
id Int @id @default(autoincrement())
email String @unique
password String
tokens String[]
created_at DateTime @default(now())
updated_at DateTime @updatedAt()
account account?
}
model account {
accNumber Int @id @default(autoincrement())
balance Float
user user @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId Int @unique
Sender transactions[] @relation("sender")
Receiver transactions[] @relation("receiver")
created_at DateTime @default(now())
updated_at DateTime @updatedAt()
}
model transactions {
id Int @id @default(autoincrement())
txRef String @unique
amount Float
refundRef String? @unique // this will reference a txRef column of a transaction whenn it is a refund
from account @relation("sender", fields: [senderId], references: [accNumber])
senderId Int
to account @relation("receiver", fields: [receiverId], references: [accNumber])
receiverId Int
created_at DateTime @default(now())
updated_at DateTime @updatedAt()
}
Please can anyone see what's wrong with the model?Nathaniel Babalola
02/01/2022, 12:34 PMNurul
02/01/2022, 12:53 PMNurul
02/01/2022, 1:01 PMfrom
when invoking prisma.transactions.create
?Nathaniel Babalola
02/01/2022, 1:03 PMNathaniel Babalola
02/01/2022, 1:05 PMNurul
02/01/2022, 1:21 PMreceiverId
and senderId
but your schema is expecting accountNumber of sender
and receiver
Nurul
02/01/2022, 1:23 PMfrom
and to
should reference to user
model and not account
model.Nathaniel Babalola
02/01/2022, 1:49 PMNathaniel Babalola
02/01/2022, 1:50 PMNurul
02/01/2022, 1:53 PM