Reputation: 45
I'm creating a table, but I get this error:
- number of referencing and referenced columns for foreign key disagree.
I don't know how to solve it. I think that it may be a problem with declaring 3 foreign keys, but, I'm not sure about it.
What is the problem?
Create table Trasllat
(
Data Date,
Codi_Empleat Integer,
Nom_agencia Varchar(30),
Data_fi Date,
Primary key (Data, Codi_Empleat),
Foreign key (Data) references Data on delete cascade,
Foreign key (Codi_empleat) references Empleat on delete cascade
Foreign key (Nom_agencia) references Agencia on delete cascade
);
Upvotes: 4
Views: 15405
Reputation: 77876
That's because you are not specifying the specific column name of the table to which it should reference to. Your Foreign key declaration should look like below. Notice the part, references Empleat(column_name)
it says that column Codi_empleat
references to Empleat
tables column_name
column.
Foreign key (Data) references Trasllat(Data) on delete cascade,
Foreign key (Codi_empleat) references Empleat(column_name) on delete cascade
Foreign key (Nom_agencia) references Agencia(column_name) on delete cascade
Check Postgres Documentation to get more information on the same.
Upvotes: 8