I keep encountering this error upon executing df.to_sql.I want to append existing data from a csv file into a MS DB file (accdb). Can you please help me out? I cant see anywhere in the internet a solution about this error.The DB has been created already, with column names but no data yet.
TypeError: has_table() got an unexpected keyword argument 'info_cache'
Here's my code:
import sqlalchemy as sa
import pandas as pd
connection_string = (
r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"
r"DBQ=C:/Users/usrname/Desktop/Folder/test.accdb;"
r"ExtendedAnsiSQL=1;"
)
connection_url = sa.engine.URL.create(
"access+pyodbc",
query={"odbc_connect": connection_string}
)
engine = sa.create_engine(connection_url)
df = pd.DataFrame({'name' : ['User 1', 'User 2', 'User 3']})
df.to_sql('users', con=engine)
I found this and it might help. It seems that SQLAlchemy verifies the database types prior the insert. There might be discrepancy with the df types and the database itself when trying to bulk insert the data. Try using the 'dtype' mapping of 'to_sql'.
SQLAlchemy Reflection Line 401