我工作的PostgreSQL数据库上,我有一个问题:PostgreSQL的外键整数[]是指整数
我想创建一个列categories_ids表申请人(即意味着申请人可以有多个类别),我想创建一个外键约束之间的这个列和类别表的列ID。但是pgAdmin的说,这是不可能的:
foreign key constraint "fk_categories_ids" cannot be implemented
DÉTAIL : Key columns "categories_ids" and "id" are of incompatible types: integer[] and integer.
编辑1:
CREATE TABLE public.applicants
(
-- Hérité(e) from table users: id integer NOT NULL DEFAULT nextval('users_id_seq'::regclass),
-- Hérité(e) from table users: email character(60) NOT NULL,
-- Hérité(e) from table users: "firstName" character(50) NOT NULL,
-- Hérité(e) from table users: "lastName" character(50) NOT NULL,
-- Hérité(e) from table users: password character(50) NOT NULL,
-- Hérité(e) from table users: role_id integer NOT NULL DEFAULT nextval('users_role_id_seq'::regclass),
home boolean NOT NULL,
"fullTime" boolean,
"partTime" boolean NOT NULL,
freelance boolean NOT NULL,
internship boolean NOT NULL,
"minSalary" integer,
domain_id integer,
categories_ids integer[],
skills_ids integer[],
locations_ids integer[],
"jobExperiences_ids" integer[],
CONSTRAINT pk_applicant_id PRIMARY KEY (id),
CONSTRAINT fk_domain_id FOREIGN KEY (domain_id)
REFERENCES public.domains (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
INHERITS (public.users)
WITH (
OIDS=FALSE
);
这根本不被支持。规范化你的数据模型,然后你可以创建一个合适的外键 –
是的,但我不知道如何建模这个配置,我真的刚开始在数据库上工作,你能告诉我怎么做? –
您正在寻找关系设计中的“一对多关系” –