我有三個表格:organization
,organization_teams
和org_users
。這裏organization_teams
從organization
繼承。因此,假設如果在organizations_teams
中添加記錄,則將獲得organization
表id
作爲id
列的值organization_teams
。PostgreSQL中的外鍵+表繼承?
org_users
有id
列的外鍵organization
。現在當我試圖插入數據在org_users
它給我錯誤如下
insert or update on table "org_users" violates foreign key constraint "org_users_organizations"
DETAIL: Key (org_id)=(12) is not present in table "organizations"
爲什麼?
序列號不是遺傳的。 – frlan
這是已知的警告:*繼承特性的嚴重限制是索引(包括唯一約束)和外鍵約束僅適用於單個表,而不適用於它們的繼承子* http://www.postgresql.org/docs/ current/static/ddl-inherit.html#DDL-INHERIT-CAVEATS – pozs
我已經在組織表中有一些組織,在organization_teams中有一些組織,因此org_user在組織中有外鍵。 –