I had this problem when I try to save a new entry into a table called 'config',
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 '''
and postgres gave such error(the app is called "pegasus" so the table name that django gives is actually "pegasus_config"):
IntegrityError: duplicate key value violates unique constraint "pegasus_config_scanner_id_name_key"
DETAIL: Key (scanner_id, name)=(2, ) already exists.
I searched in stackoverflow and found this solution, the problem is that I don't know which table should I reset the index. I did the following according to the answer:
SELECT setval('pegasus_config_id_seq', (SELECT MAX(id) FROM pegasus_config)+1)
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.