I have a data model for Tasks and Equipments.
Sometimes a Task
needs some Equipment
to be completed, sometimes it doesn't.
Task table
create table task (
id serial primary key
, task_name varchar(80)
)
Equipment table
create table equipment (
id serial primary key
, equipment_name varchar(80)
)
What I would like to do is add a null reference to the Task table
.
create table task (
id serial primary key
, task_name varchar(80)
, equipment_id serial null references equipment(id)
)
I get an error
ERROR: conflicting NULL/NOT NULL declarations for column "equipment_id" of table "task"
SQL state: 42601
How can I maintain my data integrity while adding a Foreign key to my tables so that it works as expected? I thought you could have null references.