Skip to content
Advertisement

Two composite foreign keys with one column in common

I am trying to map the following ER Model into PostgreSQL and I am having trouble with the Issue_Label table. It requires the key from the Issue table, which is id and the key from the Label table, which is the pair (id, project_id).

ER Model However, I wanna make sure the project_id from both the Issue table (which is not part of the primary key) and the Label table are the same. I tried the following:

but I keep getting this error:

How can I fix this, preferably without having to change the Issue table key?

Advertisement

Answer

If:

  • The key from the Issue table is id, and
  • The key from the Label table is the pair (id, project_id)

Then the foreign keys should take the form:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement