问题
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