title: local postgres db keeps giving error duplicate key value violates unique constraint
body: <p>I don't understand why postgres is raising: </p>
  
  <pre><code>duplicate key value violates unique constraint
  </code></pre>
  
  <p>I went to check the table in pgadmin to see if the table really did have a duplicate and see:</p>
  
  <p>Running VACUUM recommended</p>
  
  <p>The estimated rowcount on the table deviates significantly from the actual rowcount.  </p>
  
  <p>Why is this happening?  Luckily it doesn't seem to happen in production on heroku.  It's a rails app.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Here is the sql log:</p>
  
  <blockquote>
    <p>SQL (2.6ms)  INSERT INTO "favorites" ("artist_id", "author_id",
    "created_at", "post_id", "updated_at") VALUES ($1, $2, $3, $4, $5)
    RETURNING "id"  [["artist_id", 17], ["author_id", nil], ["created_at",
    Sun, 18 Mar 2012 03:48:37 UTC +00:00], ["post_id", 62], ["updated_at",
    Sun, 18 Mar 2012 03:48:37 UTC +00:00]] PG::Error: ERROR:  duplicate
    key value violates unique constraint
    "index_favorites_on_artist_id_and_post_id" DETAIL:  Key (artist_id,
    post_id)=(17, 62) already exists.</p>
  </blockquote>
  
  <p>But in the actual table there is no such record with artist_id = 17 and post_id = 62.  But postgres believes that there is.</p>