Handling PostgreSQL Integrity Errors in Django
Posted on September 18th, 2009 by Chris
I have some basic Django code that attempts to insert a new record into a PostgreSQL database. It’s wrapped in a try/except statement in case a unique constraint is violated, in which case I’ll typically ignore it and move on.
So the general pattern is:
from django.db import IntegrityError
import models
try:
myNewRecord = models.MyTable(data=blah)
[...]
2 Comments »
Filed under: Django, MySQL, PostgreSQL