python - Multiple Table Transactions SQLAlchemy -


i'm trying save 2 tables. let need insert tbl_1 first , use generated id inserted tbl_2 after insert call commit command. on current approved

tbl_1.add(data1) tbl_1.commit()  -- retrieve id tbl_1 tbl2.add(tbl_1.id, data2) tbl2.commit() 

the problem approach if tbl2.add fails need delete added tbl_1. , don't having delete action since table id incrementation messy. i'm thinking this

tbl_1.add(data1) tbl2.add(tbl_1.id, data2) tbl2.commit() 

any idea on how achieve using sqlalchemy?

***** edit ****** tbl_1 , tbl2 same session object of sqlalchemy. tried setting autocommit true , works did was

tbl_1.add(data1) tbl_1.flush() tbl2.add(tbl_1.id, data2) tbl2.commit() 

are there problems setting autocommit true or false?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -