多列主键非空约束

create table if not exists favoriteAsk (
    userID int8 references users(id) on delete cascade not null,
    createTime timestamp with time zone default now() not null,
    objectID int8 references ask(id) on delete set null,
    publisherID int8 references users(id) not null,
    objectCreateTime timestamp with time zone default now() not null,
    content varchar(65536) not null,
    typee askType not null,
    primary key (userID,objectID)
);

 

删除ask时报错

test=> delete from ask where id = 100003527 and publisherID = 100000042;
错误:  在字段 "objectid" 中空值违反了非空约束
描述:  失败, 行包含(2, 2017-07-28 14:08:29.064394+08, null, 100000042, 2017-07-28 13:11:22.826071+08, 😂😂😂😃😃😄😄😅😅☺️☺️🙃🙃😆🙃..., 急问).
背景:  SQL 语句 "UPDATE ONLY "public"."favoriteask" SET "objectid" = NULL WHERE $1 OPERATOR(pg_catalog.=) "objectid""

因为将主键设置为 primary key(userID,objectID),因而objectID不能为空,所以删除时报错了

posted @ 2017-07-28 16:05  cdongyang  阅读(611)  评论(0编辑  收藏  举报