Cannot set null value to FK - null value in column "X" of relation "Y" violates not-null constraint
Hi everyone, I'm trying to create a userId column, fk to users.id but optional (so I don't set the notNull property):
userId: char("user_id", {
length: 12,
}).references(() => users.id),
But when I try to insert a value with NULL user_id, I get the error:
null value in column "user_id" of relation "notifications" violates not-null constraint
I've read that we're supposed to be able set null as fk if notNull is not present.
I also tried with every combination of onDelete/onUpdate (set null, cascade etc.) but nothing works. Any idea?
0 Replies