On 04/09/2017 10:52 AM, SG wrote:
> I have two databases with one session for each of them.
> I would like to move objects contained in one of them to the other.
> I tried to get an object from the first with something like:
>
> |
> obj =sessionA.query(MyClass).filter(MyClass.name=='some name')
> |
>
> and then I tried to add this object to the second session with:
>
> |
> sessionB.add(obj)
> sessionB.commit()
> |
>
> but I get this exception:
>
> |
> |Object''isalready attached to session '1'(thisis'2')|
> |
>
> How could I overcome this exception and be able to move this object?
> Is there a way to do this?
This use case is covered here:
http://stackoverflow.com/questions/11213665/unbind-object-from-session
Call expunge() first.
Cheers,
M
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature