Home > database >  Force not commit on df.to_sql
Force not commit on df.to_sql

Time:04-06

I need to use pandas df.to_sql without auto commit at the end. Is there a way to do that?

Thanks

CodePudding user response:

Are you using SQLAlchemy? If so, SQLAlchemy will always commit automatically (see e.g. here) You could however use the engine.begin context manager to roll back any commits upon failure:

with engine.begin() as conn:
    df.to_sql(name= 'test1',schema='test', con=conn)
  • Related