0

I am trying to set primary key on a column (which references a parent table), but I get an error

CREATE TABLE IF NOT EXISTS matches
(
    id serial,
    user_id PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE, 
    matched_profile REFERENCES profiles(id) ON DELETE CASCADE,  
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    updated_on TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    UNIQUE (user_id, matched_profile)  
);

Not sure what's wrong here, if anyone could explain. Thanks!

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Karan Kumar
  • 1,726
  • 2
  • 12
  • 39

1 Answers1

0

Firstly you are missing data types for user_id and matched_profile.

You are also using serial when you should be using INT GENERATED ALWAYS AS IDENTITY

Wakka
  • 384
  • 8