In my airflow project i am trying to load data to mysql database using df.to_mysql method but it gives me exception AttributeError: 'Connection' object has no attribute 'cursor'

The code i am trying to execute is def load_market_data(flattened_df_json): records = json.loads(flattened_df_json) df = pd.DataFrame(records) df['from'] = pd.to_datetime(df['from']).dt.date df['volume'] = df['volume'].astype('Int64') engine = create_engine("mysql+pymysql://root:1111@localhost:3307/etl_project") with engine.connect() as conn: print("MySQL connection test:", conn.execute("SELECT 1").scalar()) try: with engine.begin() as connection: df.to_sql(name="market_data", con=connection, if_exists="append", index=False) print("✅ Data loaded successfully") except Exception as e: print("Exception while inserting to db:", str(e)) raise

pandas version is 2.3.0 sqlalchemy version is 1.4.54

Comment From: kernelism

Hey @MohammadHilal1

This is not a pandas issue. Pandas is only compatible with SQLAlchemy versions greater than 2.0.0.