I'm facing the following error when I try to create that second table and I can't figure out why. For the table patente I want to be able to have (idfuncionario, titulo) as primary keys. I already tried to put the UNIQUE constraint as "UNIQUE (idfuncionario, titulo) as suggested in other topics.
CREATE TABLE publicacao
(
idfuncionario CHAR(5) NOT NULL,
titulo VARCHAR(50) NOT NULL,
data TIMESTAMP NOT NULL,
PRIMARY KEY (idfuncionario, titulo),
FOREIGN KEY(idfuncionario) REFERENCES trabalha(idfuncionario)
);
CREATE TABLE patente
(
idfuncionario CHAR(5) NOT NULL,
titulo VARCHAR(50) NOT NULL,
datafim TIMESTAMP NOT NULL,
descricao VARCHAR(100) NOT NULL,
PRIMARY KEY (idfuncionario, titulo),
FOREIGN KEY(idfuncionario) REFERENCES trabalha(idfuncionario),
FOREIGN KEY(titulo) REFERENCES publicacao(titulo)
);
The message error:
ERROR: there is no unique constraint matching given keys for referenced table "publicacao" SQL state: 42830
I'm using Postgres 9.4 on a Windows 8.1 64bits