Skip to content Skip to sidebar Skip to footer

Sqlalchemy: Modification Of Detached Object

I want to duplicate a model instance (row) in SQLAlchemy using the orm. My first thought was to do this: i = session.query(Model) session.expunge(i) old_id = i.id i.id = None sess

Solution 1:

this case is available using the make_transient() helper function:

inst = session.query(Model).first()
session.expunge(inst)

make_transient(inst)
inst.id = None
session.add(inst)
session.flush()
print inst.id #New ID

Post a Comment for "Sqlalchemy: Modification Of Detached Object"