[Solved] pymysql.err.ProgrammingError: (1064, ‘You have an error in your SQL syntax;

[Solved] pymysql.err.ProgrammingError: (1064, ‘You have an error in your SQL syntax;

Purpose

Use pymysql to insert data into the MySQL database.

Abnormal information

code

sql_test = '''INSERT INTO "es_site" ("id", "site_name", "site_role", "url", "password", "username") VALUES (1, 'test', 'test', 'https://test.com', 'passwd', 'estest');'''
cur.execute(sql_test)
conn.commit()
cur.close()
conn.close()

Solution

The field name in sql cannot be enclosed in quotation marks. Just remove the quotation marks of the field and table name

Read More: