I do not know what is happening under the hood, but in the ORM template, the object corresponds to a specific row in a specific table. If you try to add the same object to two different tables in two different databases, this does not seem like good practice, even if the table definition is exactly the same.
What would I do to solve this problem, just create a new object that is a copy of the original object and add it to the database:
session1 = SessionSRC() session1.add(item) session1.commit() new_item = Datum(item.Key, item.Value) session2 = SessionDST() session2.add(new_item) session2.commit() print new_item in session2 # >>> True print session2.query(Datum).all() # >>> [<__main__.Datum object at 0x.......>] session2.close() session1.close()
Note that session1 does not close immediately to read the original attributes of the object when creating a new object.
source share