title: Why do I get SQL state:23503 when I try to add a constraint to an existing table in Postgres?
body: <p>I have table <code>Advisor</code> which is a special <code>User</code>and contains only <code>id</code> and <code>user_id</code> (for now!) and I'm trying to make <code>user_id</code> a foreign key with the following script:</p>
  
  <pre><code>ALTER TABLE advisor
  ADD CONSTRAINT advisor_user_id_fkey
  FOREIGN KEY (user_id) REFERENCES "user" (id);
  </code></pre>
  
  <p>Which I think should work, however I get this error:</p>
  
  <pre><code>ERROR: insert or update on table "advisor" violates foreign key constraint "advisor_user_id_fkey"
  SQL state: 23503
  Detail: Key (user_id)=(44) is not present in table "user".
  </code></pre>
  
  <p>I thinks this is weird because I'm saying it should refer to <code>user.id</code> and not <code>user.user_id</code>, but obviously I'm doing something wrong. 
  Does anyone have any idea about this? Thanks.</p>
  
  <p><strong>update:</strong> if anyone is wondering why "user" and not user, well pgAdmin doesn't like user, because it thinks it's the owner of the database.</p>