我有两个表:entitytype 和project。以下是建表语句:
Create table project (
pname varchar(20) not null,
primary key(pname)
);
create table entitytype(
entityname varchar(20) not null,
toppos char(100),
leftpos char(100),
pname varchar(20) not null,
primary key(entityname),
foreign key(pname) references project(pname) on delete cascade on update cascade
);
当我尝试向 entitytype 表中插入任何值时,出现以下错误:
ERROR: insert or update on table "entitytype" violates foreign key constraint "entitytype_pname_fkey"
Detail: Key (pname)=(494) is not present in table "project".
任何人都可以阐明我做错了什么吗?
最佳答案
该错误消息表示您正在尝试添加没有相应项目条目的实体类型。 (我不知道你的领域或你想要实现的目标,但我觉得模式设计不对......)
关于sql - 在表上插入或更新违反外键约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2444899/