ProgrammingError:1054(42S22):“字段列表”中的未知列“ Lucas_Johnson”

时间:2018-10-25 12:30:51

标签: mysql python-2.7

我正在尝试插入MySQL数据库,这给了我错误:

ProgrammingError: 1054 (42S22): Unknown column 'Lucas_Johnson' in 'field list'

命令是:

c.execute("INSERT INTO master (ID, Name, Location, DateTime, Status, flagged) VALUES("+str(id)+","+str(name)+","+place+","+date.replace(':','-').replace(' ', '_')+", 'Out', "+str(flagged)+")")

1 个答案:

答案 0 :(得分:0)

这是因为在SQL字符串中缺少正确的引号。您可以在执行之前先打印字符串,然后再看到它。

但是您没有使用正确的方法来执行此操作。这样,您就可以以一种易于SQL注入的方式来编写SQL字符串。

正确的方法是

c.execute("INSERT INTO master (ID, Name, Location, DateTime, Status, flagged) VALUES(%s, %s, %s, %s, %s, %s)", (id, name, place, date.replace(':','-').replace(' ', '_'), 'Out', flagged)