Last active
March 20, 2024 06:56
-
-
Save birgersp/f902625ed25a4394406aed5f51847976 to your computer and use it in GitHub Desktop.
Add (change) foreign key constraint to an existing column in PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://dba.stackexchange.com/questions/323851/add-foreign-key-constraint-to-existing-column-while-auto-generating-the-key-nam | |
alter table "Message" | |
-- drop the old constraint | |
drop constraint "Message_sender_fkey", | |
-- (re)add constraint but this time with cascading | |
add foreign key ("sender") references "Sender"("id") on delete cascade; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment