postgresql - 引用表“employees”的给定键没有唯一约束匹配
问题描述
CREATE TABLE office(
office_id INTEGER NOT NULL PRIMARY KEY
,office_name VARCHAR(15) NOT NULL
);
CREATE TABLE category(
category_id INTEGER NOT NULL PRIMARY KEY
,category_name VARCHAR(15) NOT NULL
);
CREATE TABLE employee(
employee_id INTEGER NOT NULL
,Firstname text NOT NULL
,birthdate DATE NOT NULL
,Register text NOT NULL
,Lastname text NOT NULL
,Gender text NOT NULL
,category_id INTEGER NOT NULL
,office_id INTEGER NOT NULL
,user_name text NOT NULL
,pass_word text NOT NULL,
foreign key(category_id) references category(category_id),
foreign key(office_id) references office(office_id),
primary key(employee_id,category_id,office_id),
UNIQUE(Firstname)
);
在此之后我想创建这个表,但它给了我“没有唯一约束匹配给定键的引用表“员工”这个错误我不知道如何解决这个问题?
CREATE TABLE employee_phone(
employee_id INTEGER NOT NULL
,phone INTEGER NOT NULL,
foreign key(employee_id) references employees(employee_id),
primary key(employee_id)
);