Asa Carter
Asa Carter

Reputation: 2225

Optional Foreign key

I have a MySQL database table with a column (integer) that references a column in another table with a foreign key.

I want the value to be optional. If I try to update the value to 0 (a value that doesn't exist in the other table), the query fails.

How can I use a foreign key while keeping the value in the column optional?

Upvotes: 1

Views: 2802

Answers (1)

Uueerdo
Uueerdo

Reputation: 15941

Duplicating my comment so the question can be marked as answered.

Foreign key constraints can be made optional by simply making the referencing field(s) nullable.

Upvotes: 7

Related Questions