Postgresql constraint Postgresql constraint postgresql postgresql

Postgresql constraint


It would help if you posted the error message. But I think you are just missing the parenthesis:

ALTER TABLE my_table ADD CONSTRAINT my_fk FOREIGN KEY (my_field) REFERENCES my_foreign_table ON DELETE CASCADE;


Just guessing: shouldn't you add a foreign key instead of a constraint?

ALTER TABLE my_table ADD FOREIGN KEY (my_field) REFERENCES my_foreign_table;

Postgresql reference


I'm still somehow missing here an answer with foreign column (foreign_field) explicitly specified:

ALTER TABLE my_tableADD CONSTRAINT my_fkFOREIGN KEY (my_field)REFERENCES my_foreign_table (foreign_field)ON DELETE CASCADE;