title: Django : Deduce duplicate key exception from IntegrityError
body: <p>With Django 1.6, I get an exception when there's a duplicate key </p>
  
  <pre><code>IntegrityError: duplicate key value violates unique constraint "..."
  </code></pre>
  
  <p>Django uses <code>IntegrityError</code> exception for other types of database violations too. I want to handle the <code>duplicate key</code> as a special case i.e. </p>
  
  <pre><code>try:
      model = MyModel(name='xyz')
      model.save()
  except MyModal.IntegrityError:
      if exception_due_to_duplicate_key:
          do_something()
  except:
      do_something_else()
  </code></pre>
  
  <p>Is there a unique error code for that or will I have to parse the error message. I'm trying to avoid <code>get</code> call to database to ascertain that violation is due to a duplicate key.</p>
  
  <p><strong>Update</strong>: I should mention that exception is thrown by <code>psycopg2</code> since I'm using Django with PostgreSQL.</p>