Project

General

Profile

[DBO] Missing "unique" constraint on the foreign key in a 1-to-1 relationship.

Added by Plug Gulp over 2 years ago

I created a 1:1 relationship between two tables using DBO and looked at the generated constraints on the foreign key of the "owned" table. I see that the unique constraint is missing on the foreign key. This means there is no difference between 1:1 and 1:m relationships. I also checked the DBO tutorial and the SQL statement for the settings table is listed as:

create table "settings" (
    ...

    "user_id" bigint,
    constraint "fk_settings_user" foreign key ("user_id") references "user" ("id") deferrable initially deferred
)

Is the missing unique constraint valid? In that case, how is the 1:1 and 1:m relationship differentiated?