Tuesday, May 31, 2011

Django "duplicate key value violates unique constraint"

The few times that I have seen this error in my own code, finding the source and squashing any related bugs was pretty easy. For the first time today, I saw it appear when I was using the provided admin interface to add a user to my project where I was using django.contrib.auth. It caused me to panic a little.

With a little bit of google searching, I found this post on the django google group that helped me fix my problem clearly and quickly.

I am using a postgres back end, and it seems like the counter for the serial field was reset. By looking at the table and finding which value should come next, I was able to set this counter to the proper value, and so far everything is working great.

No comments:

Post a Comment