I've come across a problem in my app I'm writing, that I can't figure out.
I'm trying to handle the exception raised when I try to add a duplicate
entry to my database (which obviously shouldn't be allowed to occur).
From the looks of things, SQLObject throws an IntegrityError when I try
and add a duplicate entry:
IntegrityError: (1062, "Duplicate entry 'tjl2.com.' for key 2")
However, when I use a try & except block to catch this, I get the
following error:
NameError: global name 'IntegrityError' is not defined
How am I supposed to catch the IntegrityError exceptions?
Here is the relevant code from my controller:
timeTuple = time.localtime(time.time())
initSerial = int(time.strftime("%Y%m%d01",timeTuple))
try:
zone = Zone(zone=zoneName, serial=initSerial)
except IntegrityError:
turbogears.flash("Zone '"+zoneName[0:-1]+"' already exists!")
raise cherrypy.HTTPRedirect("/"+zone.zone)
Thanks in advance for any help,
Tim