小编use*_*355的帖子

错误:"表中没有键..."

我有一个表格,其中包含一个字符变化(12)字段,这是它的PRIMARY KEY.我跑了这个查询

SELECT * FROM bg WHERE bg_id ='470370111002'
Run Code Online (Sandbox Code Playgroud)

它从表中选择一行.一切看起来都不错 然后我试试.

INSERT INTO csapp_center_bgs(bg_id,center_id) VALUES('470370111002',2)
Run Code Online (Sandbox Code Playgroud)

bg_id上有一个外键,看起来像......

ALTER TABLE csapp_center_bgs
ADD CONSTRAINT csapp_center_bgs_bg_id_65c818f360c84dc5_fk_bg_bg_id
FOREIGN KEY (bg_id)
REFERENCES tiger.bg (bg_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED;
Run Code Online (Sandbox Code Playgroud)

这是精确的错误......

    ERROR:  insert or update on table "csapp_center_bgs" violates foreign key constraint "csapp_center_bgs_bg_id_65c818f360c84dc5_fk_bg_bg_id"
DETAIL:  Key (bg_id)=(470370111002) is not present in table "bg".
********** Error **********

ERROR: insert or update on table "csapp_center_bgs" violates foreign key constraint "csapp_center_bgs_bg_id_65c818f360c84dc5_fk_bg_bg_id"
SQL state: …
Run Code Online (Sandbox Code Playgroud)

postgresql inheritance constraints foreign-keys search-path

5
推荐指数
1
解决办法
8819
查看次数