Adding a column as a foreign key gives ERROR column referenced in foreign key constraint does not exist

前端 未结 5 559
抹茶落季
抹茶落季 2021-01-31 13:02

I have the following set up,

CREATE TABLE auth_user ( id int PRIMARY KEY );
CREATE TABLE links_chatpicmessage ();

I\'m trying to add a

5条回答
  •  孤城傲影
    2021-01-31 13:46

    You can do this in Postgres on one line:

    ALTER TABLE links_chatpicmessage ADD COLUMN sender INTEGER REFERENCES auth_user (id);
    

    You don't need to manually set a name. Postgres will automatically name this constraint "links_chatpicmessage_auth_user_id_fkey".

提交回复
热议问题