ERROR: null value in column "user_id" of relation "order" violates not-null constraint

33 Views Asked by At

I'm trying to create new table and insert new record but I get an error that tells me that my foreign key is not nullable. But, as I understood, it is not. So here's my record where I try to insert the record:

create table user_account
(
    user_id      bigserial
        primary key,
    ...
);

CREATE TABLE IF NOT EXISTS tip.order(
    order_id BIGSERIAL PRIMARY KEY,
    user_id BIGSERIAL,
    CONSTRAINT "user" FOREIGN KEY(user_id) REFERENCES user_schema.user_account(user_id) ON DELETE CASCADE
);

Here's full error:

ERROR: null value in column "user_id" of relation "order" violates not-null constraint (SQLSTATE 23502)

So I don't understand why is it happening. If you know what can be the problem, please tell me, I would really appreciate it!

0

There are 0 best solutions below