【发布时间】:2014-08-13 03:53:19
【问题描述】:
我有三个表:organization、organization_teams 和 org_users。这里organization_teams 继承自organization。所以假设如果在organizations_teams 中添加一条记录,它将获得organization 表id 作为organization_teams 中id 列的值。
org_users 在organization 的id 列上有外键。现在,当我尝试在 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"
为什么?
【问题讨论】:
-
没有。序列不是继承的。
-
这是已知的警告:继承功能的一个严重限制是索引(包括唯一约束)和外键约束仅适用于单个表,而不适用于它们的继承子表 postgresql.org/docs/current/static/…
-
我已经有一些组织在组织表和组织_团队中,所以 org_user 在组织上有外键。