I have two tables "Persona" (Person) and "Dona" (Female) and I want to alter a third one named "Baptisme" (Baptism), but I'm having some problems.
These are my tables:
CREATE TABLE baptismes.Persona (
id SERIAL PRIMARY KEY,
nom VARCHAR(255),
nom_complementari1 VARCHAR(255),
nom_complementari2 VARCHAR(255),
nom_complementari3 VARCHAR(255),
nom_complementari4 VARCHAR(255),
cognom1 VARCHAR(255),
cognom2 VARCHAR(255),
lloc_naixement VARCHAR(255) REFERENCES baptismes.Poblacio(nom),
data_naixement baptismes.Data,
alies VARCHAR(255),
sexe CHAR(1),
difunt BOOLEAN
);
CREATE TABLE baptismes.Dona (
cognom_marit_actual VARCHAR(255),
cognom_marit_anterior VARCHAR(255)
) INHERITS (baptismes.Persona);
CREATE TABLE baptismes.Baptisme (
id SERIAL PRIMARY KEY,
...
);
Baptisme has more attributes but they doesn't matter here.
What I'm trying to do is:
ALTER TABLE baptismes.baptisme
ADD COLUMN mare INTEGER REFERENCES baptismes.Dona(id);
but this gives me the following error:
ERROR: no hay restricción unique que coincida con las columnas dadas en la tabla referida «dona»
********** Error **********
ERROR: no hay restricción unique que coincida con las columnas dadas en la tabla referida «dona»
SQL state: 42830
In english: "there's no unique constraint matching given keys for referenced table <>".
I can't understand because Dona gets PK from Persona (id), so it should be UNIQUE.
Can somebody help me, please? Thanks!