I have dataframe which I want to load into existing mysql database table. Dataframe column names matches names in database table. Loading data works but table structure (column datatypes) are changed. Also I have in same database table additinal field TIMESTAMP type which is automticallly updated when data is inserted but somehow this field does not exist anymore after dataframe is loaded.
Here is the code how I'm connecting to mysql:
import pandas as pd
import pymysql
import pyodbc
from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('mysql+pymysql://{0}:{1}@{2}:{3}/{4}'.format(mysql["user"], mysql["pw"], mysql["host"], mysql["port"], mysql["database"]))
Base = declarative_base()
Base.metadata.reflect(engine)
df.to_sql('mytable', con = engine, if_exists = 'replace', chunksize=1000, index = False)