PrismaP
Prisma10mo ago
8 replies
josephjnk

Getting foreign key error even though foreign row exists

I have two tables connected by a foreign key constraint. My
foo
table has a
foo_uuid
column, and my
bar
table references it via a
foo_uuid
column. I am trying to call this method:
prismaClient.bar.create({
  data: {
    foo_uuid: 123,
    other_bar_field: "whatever"
  }
})


I have DBeaver open and can see that there is a row in the
foo
table with
foo_uuid = 123
, but when I run the
create
method I get an error: "Foreign key constraint violated". It has code
P2003
and says the error is on the
foo_uuid
foreign key constraint.

Thing is, not only does the
foo
exist, but I can also insert this row into
bar
using DBeaver without any errors. What's going on? Is there some additional argument that's needed for the
create
call when a foreign key exists?
Was this page helpful?