asdasdas
asdasdas

Reputation: 301

add NULL in foreign key

I know it is possible to allow NULL in foreign key but I'm having a hard time looking for an answer. I'm using postgresql and the command "ALTER TABLE table_name ALTER COLUMN column_name INT NULL" did not work. I used this so that my foreign key will allow NULL in it. How to do it right in postgresql?

Here's my table definition:

CREATE TABLE table1."authorization"
(
  authorization_id integer NOT NULL DEFAULT nextval('table1.authorization_seq'::regclass),
  process_id integer,
  site_id integer,
  parent_opted_out boolean,
  CONSTRAINT table1_pk PRIMARY KEY (authorization_id ),
  CONSTRAINT table2_fk FOREIGN KEY (process_id)
      REFERENCES table2.process (process_id) MATCH Unknown
      ON UPDATE NO ACTION ON DELETE NO ACTION
)

Upvotes: 1

Views: 73

Answers (1)

Mureinik
Mureinik

Reputation: 312344

Your syntax is wrong. To remove the not null modifier from a column, you should use:

ALTER TABLE table_name ALTER COLUMN column_name DROP NOT NULL

Upvotes: 1

Related Questions