【发布时间】:2014-07-17 01:00:10
【问题描述】:
我有这张桌子:
CREATE TABLE operation_history
(
id bigserial NOT NULL,
task_history bigint NOT NULL,
operation smallint NOT NULL,
CONSTRAINT operation_history_pkey PRIMARY KEY (id),
CONSTRAINT operation_history_operation_fkey FOREIGN KEY (operation)
REFERENCES desktop_operation (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT operation_history_task_history FOREIGN KEY (task_history)
REFERENCES task_history (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
我有另一个表 task_history,其中包含三行,ID:1、2、3。但是,由于某种原因,当我在 operation_history 表上插入时,我收到一个错误,提示 task_history 行不存在我给它的 id。这是要插入的查询:
INSERT INTO operation_history (task_history, operation) VALUES
(1, 2);
这是错误:
ERROR: insert or update on table "operation_history" violates foreign key constraint "operation_history_task_history"
DETAIL: Key (task_history)=(1) is not present in table "task_history".
不过,我确信 task_history 表中有三行 ID 分别为 1、2 和 3。
这可能是什么原因造成的,我该如何补救?
【问题讨论】:
-
极不可能.. 看到这个小提琴sqlfiddle.com/#!15/999e7/1
标签: sql postgresql postgresql-9.1 postgresql-9.2 postgresql-9.3