I cannot seem to get this right, I am trying to modify a field to be a foreign key, with cascading delete... what am i doing wrong?
ALTER TABLE my_table
ADD CONSTRAINT $4
FOREIGN KEY my_field
REFERENCES my_foreign_table
ON DELETE CASCADE;
I cannot seem to get this right, I am trying to modify a field to be a foreign key, with cascading delete... what am i doing wrong?
ALTER TABLE my_table
ADD CONSTRAINT $4
FOREIGN KEY my_field
REFERENCES my_foreign_table
ON DELETE CASCADE;
This works to me, I add the column to the table and then add the constraint with references to the other table:
Just guessing: shouldn't you add a foreign key instead of a constraint?
Postgresql reference
I'm still somehow missing here an answer with foreign column (
foreign_field
) explicitly specified:It would help if you posted the error message. But I think you are just missing the parenthesis: