Home > database >  df to table throw error TypeError: __init__() got multiple values for argument 'schema'
df to table throw error TypeError: __init__() got multiple values for argument 'schema'

Time:01-30

I have dataframe in pandas :- purchase_df. I want to convert it to sql table so I can perform sql query in pandas. I tried this method

purchase_df.to_sql('purchase_df', con=engine, if_exists='replace', index=False)

It throw an error

TypeError: __init__() got multiple values for argument 'schema'

I ran this code in pycharm locally and it work perfectly fine but when i tried this in databrick notebook it is showing an error. Even though week ago it was running fine in databrick notebook too. Help me to fix this.

note:- pandas version '1.3.4' Name: SQLAlchemy Version: 2.0.0

CodePudding user response:

It seems that the version 2.0.0 (realeased on January 26, 2023) of SQLAlchemy is not compatible with earlier versions of . I suggest you to upgrade your pandas version to the latest (version 1.5.3) with :

pip install --upgrade pandas

Or:

conda upgrade pandas

CodePudding user response:

The error you are encountering is because the to_sql method is getting multiple values for the argument schema. One possible solution is to specify the schema argument with a value. For example, you can do:

purchase_df.to_sql('purchase_df', con=engine, if_exists='replace', index=False, schema='my_schema')

This should resolve the issue with the schema argument. If the problem persists, it is possible that there is a version mismatch between pandas and SQLAlchemy or other dependencies. Try updating them to the latest version to see if that fixes the issue.

  • Related