On 9/21/2010 7:31 AM, Michael Hipp wrote:
I need to "empty" an item (row). I thought to do this:
new = Item() # create a new empty object
new.id_ = old.id_ # copy certain other fields also
self.session.expunge(old)
self.session.add(new)
self.session.commit()
But it seems SA still tries to save it with an INSERT. (I thought the presence
of the PK was what determined that.)
Is there some way to "blank" a record and save it back with the same PK and a
few other select fields that need to be kept?
I continue to play with this. It reads like 'merge' would do exactly what I
want, but I must be misunderstanding it.
http://www.sqlalchemy.org/docs/orm/session.html#merging
Changing the 'session.add' line to 'session.merge' still produces
IntegrityError: duplicate key value violates unique constraint
Trying it with and without the 'expunge' line just changes the error to
New instance ... conflicts with persistent instance
Can anyone suggest an approach to "empty" a record?
Thanks,
Michael
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.