这是我的问题的一个简单示例
CREATE TABLE parent (
id SERIAL PRIMARY KEY
);
CREATE TABLE child (
name text
) INHERITS (parent);
-- Populating child table
INSERT INTO child (name) VALUES ('Alex');
INSERT INTO child (name) VALUES ('Simba');
INSERT INTO child (name) VALUES ('Jafar');
CREATE TABLE test(
parentId INTEGER REFERENCES parent (id)
)
-- I checked Alex has id of 1 and it is present in parent table
INSERT INTO test(parentId) VALUES (1);-- This line does not work
我收到以下消息: 插入test(parentId)值(1)
错误:在表“ test”上进行插入或更新违反了外键约束“ test_parentid_fkey” 详细信息:表“父母”中没有键(父母)=(1)。
为什么会出现此错误?