title: PostgreSQL: Column Reference in Foreign Key Constraint Does Not Exist
body: <p>I'm still new to postgreSQL.  I have two tables I created that I want to go back and add Primary and Foreign key constraints for and no matter what I do I can't seem to add a foreign key.  Here's what I have:</p>
  
  <p>Two Tables:</p>
  
  <pre><code>test=# \d statename
        Table "public.statename"
   Column |     Type      | Modifiers
  --------+---------------+-----------
   code   | character(2)  | not null
   name   | character(30) |
  Indexes:
      "statename_pkey" PRIMARY KEY, btree (code)
  
  test=# \d customer
            Table "public.customer"   
      Column   |     Type      | Modifiers
  -------------+---------------+-----------
   customer_id | integer       |
   name        | character(30) |
   telephone   | character(20) |
   city        | character(25) |
   street      | character(40) |
   state       | character(2)  |
   zipcode     | character(10) |
   country     | character(20) |
  </code></pre>
  
  <p>Here's the command I'm running:</p>
  
  <pre><code>test=# ALTER TABLE customer ADD CONSTRAINT
  state FOREIGN KEY (code) REFERENCES
  statename (code) &gt;MATCH FULL;
  </code></pre>
  
  <p>Here's the error I'm getting:</p>
  
  <pre><code>ERROR:  column "code" referenced in foreign key constraint does not exist
  </code></pre>
  
  <p>I'm looking at the column!  I know it exists!  Please help a brother out!</p>