python - insert into table from another table with alembic -
i have 2 tables linked id (their foreign key). want write alembic script to:
1.get rows in table #1 column_name = null
2.for each row, insert new row table #2.
3.update table #1’s null column_name fields newly inserted fields in table #2 (where table#1.col.id = table#2.col.id):
how can newly inserted ids in table #2 in order update column_name in table #1? following approach correct:
def upgrade(): conn = op.get_bind() rows = conn.execute( sa.select([ table1.id.label('id'), ]).where( table1.column_name_is_(none) ) ).fetchall() how can optimize use of update , insert?
Comments
Post a Comment