0
我有一個PostgreSQL數據庫,3個表和我的架構如下PostgreSQL中違反外鍵約束與傳承
--- Parent Table
CREATE TABLE IF NOT EXISTS abc.parent(
record_id SERIAL PRIMARY KEY,
description text NOT NULL
);
--- Child Table
CREATE TABLE IF NOT EXISTS abc.child (
total_count INT NOT NULL) INHERITS (abc.parent);
-- Detail
CREATE TABLE abc.detail(
detail_id int NOT NULL,
detail_description text NOT NULL
record_id int NOT NULL,
FOREIGN KEY (record_id) REFERENCES abc.parent(record_id)
);
然後我插入記錄雙方父母與子女表。
家長
|record_id|description|
|1 |abcd |
|2 |efgh |
孩子
|record_id|description|total_count|
|3 |xygh |5 |
|4 |mnop |7 |
當我嘗試插入記錄到以下兩個entires詳細信息表被成功
Detail
|detail_id|detail_description|record_id|
|100 |detail_desc1 | 1 |
|200 |detail_desc2 | 2 |
,但我不能插入帶有RECORD_ID 3項它給了我一個外鍵違規錯誤
有人可以解釋這個錯誤嗎?
我們可以建立在PostgreSQL這樣的外鍵關係與繼承