OperationalError Traceback (most recent call last)
<ipython-input-7-e63de1bbf3b5> in <module>()
1 for row in df.iterrows():
2 sql = 'INSERT INTO salesdata ({}) VALUES ({})'.format(','.join(df.columns), ','.join(['?']*len(df.columns)))
----> 3 c.execute(sql, tuple(row[1]))
4 conn.commit()
I get OperationalError: near "System": syntax error . I tried inserting more space and removing space between single quotes it does not work. How do I make this code work?
Presumably one of your column names is System
. This is a reserved word in MySQL 8.0, so it needs to be escaped. You should surround all the column names with backticks.
sql = 'INSERT INTO salesdata ({}) VALUES ({})'.format(','.join('`' + col + '`' for col in df.columns), ','.join(['?']*len(df.columns)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.