Hello! (Sorry about my english :) )
I'm trying to resolve this by myself, but i can't. So, I hope you can help me.
I'm getting an IntegrityException when I try to delete an object,
because that object is still referenced in the database.
I want to catch that error and follow with my program normally, but I
don't know how. It's like if the rollback is not being executed,
because I get again the exception at the moment of the commit()
My session is autoflush=True and transactional=True
class child(object):
def __init__(self , valor):
self.valor = valor
class father(object):
def __init__(self , cantidad , idChild):
self.cantidad = cantidad
self.idChild = idChild
metadata = MetaData()
childTabla = Table ('child' , metadata ,
Column('id' , Integer , primary_key = True) ,
Column('valor' , Float , nullable = False)
)
mapper(child,childTabla)
fatherTabla = Table('father' , metadata ,
Column('id' , Integer , primary_key = True) ,
Column('cantidad', Integer , nullable=False),
Column('child_id', Integer ,
ForeignKey('child.id') , nullable=False),
)
mapper(father, fatherTabla , properties={'child':synonym('child_id')})
p = session.query(father).first()
c = session.query(child).first()
try:
session.delete(c)
except:
session.rollback()
p.child = 2
session.update(p)
session.commit()
So, how is the correctly way to do this?
Thaks a lot!!
--
Marcos Alcazar
Mendoza, Argentina
O< ascii ribbon campaign - stop html mail -
http://www.asciiribbon.org/index-es.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---