Pandas to_sql in django
It is possible to create db configuration in setting.py file
DATABASES = { 'default': env.db('DATABASE_URL_DEFAULT'), 'other': env.db('DATABASE_URL_OTHER')}DB_URI_DEFAULT=env.str('DATABASE_URL_DEFAULT')DB_URI_OTHER=env.str('DATABASE_URL_OTHER')
If you want to create sql_alchemy connection you should use DB_URI_DEFAULT or DB_URI_OTHER
in the init method of the class you will use .to_sql method you should write
from you_project_app import settingsfrom sqlalchemy import create_engineimport pandas as pdclass Example: def __init__(self): self.conn_default = create_engine(settings.DB_URI_DEFAULT).connect()
And when you use .to_sql method of pandas it should be like this:
df_insert.to_sql(table, if_exists='append',index=False,con=self.conn_default)