title: django: IntegrityError: duplicate key value violates unique constraint
body: <p>I had this problem when I try to save a new entry into a table called 'config',</p>
  
  <pre><code>class Config(models.Model):
      ident = models.CharField(max_length=uuidLength, null=True, editable=False)
      scanner = models.ForeignKey('Scanner')
      name = models.CharField(max_length=64)
     ''' some other fields '''
  </code></pre>
  
  <p>and postgres gave such error(the app is called "pegasus" so the table name that django gives is actually "pegasus_config"):</p>
  
  <pre><code>IntegrityError: duplicate key value violates unique constraint "pegasus_config_scanner_id_name_key"
  DETAIL:  Key (scanner_id, name)=(2, ) already exists.
  </code></pre>
  
  <p>I searched in stackoverflow and found <a href="https://stackoverflow.com/questions/11089850/integrityerror-duplicate-key-value-violates-unique-constraint-django-postgres">this</a> solution, the problem is that I don't know which table should I reset the index.
  I did the following according to the answer:</p>
  
  <pre><code>SELECT setval('pegasus_config_id_seq', (SELECT MAX(id) FROM pegasus_config)+1)
  </code></pre>
  
  <p>but the problem still exists. I also went into database and found that "pegasus_config_scanner_id_name_key" is actually an index. So I'm confused about which index to reset? Please help. Thanks.</p>