Reputation: 2225
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
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