Postgresql constraint

前端 未结 4 1156
终归单人心
终归单人心 2021-02-06 21:23

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 CON         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 21:49

    This works to me, I add the column to the table and then add the constraint with references to the other table:

    -- add column to table 
    ALTER TABLE schema.table ADD COLUMN my_column type;  
    
    -- add constraint to column 
    ALTER TABLE schema.table ADD CONSTRAINT fk_name FOREIGN KEY (column)
    REFERENCES schema.table (column) MATCH SIMPLE 
    ON UPDATE NO ACTION ON DELETE NO ACTION; 
    

提交回复
热议问题