SQLAlchemy - how to get class for existing database table and then update that table

孤人 提交于 2020-01-25 03:09:26

问题


I have an existing database (SQLite) and am trying to update a table in the database from an excel file. I'm bringing the excel data into python using pandas. It's in a dataframe with the index set to the same keys that are in the target database table.

I'm trying to use sqlalchemy to batch update the database table, but I am having trouble defining the class. The database already exists, so I need to extract the class information.

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

connection = engine.connect()
Session = sessionmaker(bind=engine)
session = Session()
session.bulk_insert_mappings(myTableName, df.to_dict)
session.commit()
session.close()

来源:https://stackoverflow.com/questions/54540938/sqlalchemy-how-to-get-class-for-existing-database-table-and-then-update-that-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!