Tag Archives: pymysql.err.OperationalError: (1054, “Unknown column’aa’in’field list’)

pymysql.err.OperationalError: (1054, “Unknown column’aa’in’field list’)

Error Description:

Today, when using Python to connect to MySQL database for data addition, an error “pymysql. Err. Operationalerror: (1054,” unknown column ‘AA’ in ‘field list’) “appears. After query, it is because when pymysql inserts data, if it is of type vchar or string, it needs single quotation marks to insert successfully.

Solution:

Modify the SQL statement using the repr() function in Python:

Original SQL statement:

sql = "INSERT INTO student(name,sex,age,grade) VALUES ("+name+","+sex+","+age+","+grade+")"

Modified SQL statement:

sql_0="INSERT INTO student(name,sex,age,grade) VALUES (%s,%s,%s,%s)"
sql=sql_0 % (repr(name), repr(sex),repr(age),repr(grade))