1

I see lots of this question is about sqlite, but mine is to MySQL.

my entire script is like this:

df = pd.read_csv("df.csv")
engine = sqlalchemy.create_engine('mysql+mysqlconnector://{0}:{1}@{2}/{3}'.
                                               format(config.user, config.passwd, 
                                                      config.host, config.db))

df.to_sql('SQL_table', con=engine, if_exists='append', index=False)

Then it returns the error:

 'Engine' object has no attribute 'cursor'

I googled, and followed some solutions, one of them is:

df = pd.read_csv("df.csv")
engine = sqlalchemy.create_engine('mysql+mysqlconnector://{0}:{1}@{2}/{3}'.
                                                   format(config.user, config.passwd, 
                                                          config.host, config.db))

connection = engine.raw_connection()    
df.to_sql('SQL_table', con=connection, if_exists='append', index=False)

Then the error changed to:

DatabaseError: Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': Not all parameters were used in the SQL statement

I am using MySQL, not sqlite, i don't understand why it returns this error.

So basically, i think the solution is not working, and would anyone please tell me how to fix this problem, my SQLalchemy is 1.4.27

EntzY
  • 467
  • 4
  • 11

1 Answers1

0

I have solved this, i reset my Mac, then come back to my VS Code, and start the notebook again, the problem is gone.

But before that, i tried also using command

reset

that can't do the trick. It has to be machine hard reset.

EntzY
  • 467
  • 4
  • 11