to_sql pandas method changes the scheme of sqlite tables

后端 未结 1 582
借酒劲吻你
借酒劲吻你 2021-01-05 03:57

When I write Pandas DataFrame to my SQLite database using to_sql method it changes the .schema of my table even if I use if_exists=\'append\'. For

相关标签:
1条回答
  • 2021-01-05 04:29

    Starting from 0.14 (what you are using), the sql functions are refactored to use sqlalchemy to improve the functionality`. See the whatsnew and docs on this.
    The raw sqlite3 connection is still supported as a fallback (but that is the only sql flavor that is supported without sqlalchemy).

    Using sqlalchemy should solve the issue. For this you can just create a sqlalchemy engine instead of the direct sqlite connection cnx:

    engine = sqlalchemy.create_engine('sqlite:///my_db.sqlite')
    df.to_sql('Resolved', engine, if_exists='append')
    

    But I filed an issue for the case with the sqlite cnx fallback option: https://github.com/pydata/pandas/issues/7355

    0 讨论(0)
提交回复
热议问题