_mysql_exceptions.ProgrammingError: (1064, "你的 SQL 语法有错误;

pym*_*mat 1 mysql python-3.6

        sql = ("INSERT INTO {0} "
               "(id, timestamp, status, priority, client, group, capacity, level, mail_id) "
               "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)".format(TABLE_NAME_MAIL))
        values = ('NULL', report['timestamp'], 'succeeded', report['priority'], c.strip(), report['group'], 'NULL', 'NULL', ref_mailid)
        cursor.execute(sql, values)
        #cursor.execute('INSERT INTO %s VALUES (NULL,"%s","%s","%s","%s","%s",NULL,NULL,"%s") ' % (TABLE_NAME_REPORT, report['timestamp'], 'succeeded', report['priority'], c.strip(), report['group'], ref_mailid))
Run Code Online (Sandbox Code Playgroud)

注释掉的cursor.execute工作,未注释的抛出错误:

_mysql_exceptions.ProgrammingError: (1064, "您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以获取在 'group, capacity, level, mail_id 附近使用的正确语法) VALUES ('NULL', ' 2014-12-05 23:46:56',在第 1 行'成功'")

列“ id”有AUTO_INCREMENT

为什么我收到这个错误?

jue*_*n d 5

groupMySQL 中保留关键字。使用反引号来转义名称

INSERT INTO {0} (id, timestamp, status, priority, client, `group`, capacity ...
                      here--------------------------------^-----^
Run Code Online (Sandbox Code Playgroud)

甚至更好地使用不同的列名。

并且不要'NULL'用作参数。使用NULL不带引号或从查询中完全删除它:

INSERT INTO {0} (timestamp, ...
                ^----------no ID
Run Code Online (Sandbox Code Playgroud)