小编典典

没有唯一约束匹配给定键的引用表

sql

我有一个date_dimension表定义:

CREATE TABLE date_dimension
(
  id integer primary key,
  date text,
  year double precision,
  year_for_week double precision,
  quarter double precision
);

我正在尝试创建fact失败的表

create table fact ( 
  id serial primary key,
  contract integer,
  component integer,
  evaluation_date integer,
  effective_date integer,
  foreign key (evaluation_date, effective_date) references date_dimension(id, id)
);

错误是:

ERROR:  there is no unique constraint matching given keys for referenced 
table "date_dimension"

SQL state: 42830

我不确定如何解决此问题。


阅读 252

收藏
2021-04-07

共1个答案

小编典典

我认为您正在寻找两个单独的外键:

foreign key (evaluation_date) references date_dimension(id),
foreign key (effective_date) references date_dimension(id)
2021-04-07