mysql python错误1064,mysql sytax错误

dbf7pr2w  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(413)

我现在有一些问题,当我试图插入一行到一个数据库,这也工作过,虽然它只是现在,我已经添加了“键”列,它无法工作,并给我一个错误。

add = ("INSERT INTO server_stats_servers "
            "(Owner, ServerID, MessageID, Channel, ServerIP, ServerPort, ServerName, DiscordName, Key)"
            "VALUES (%(Owner)s, %(ServerID)s, %(MessageID)s, %(Channel)s, %(ServerIP)s, %(ServerPort)s, %(ServerName)s, %(DiscordName)s, %(Key)s)")
    values = {"Owner": owner,
            "ServerID": serverid,
            "MessageID": messageid,
            "Channel": channel,
            "ServerIP": ip,
            "ServerPort": port,
            "ServerName": servername,
            "DiscordName": discordname,
            "Key": key,}
    cursor.execute(add, values)
    cnx.commit()

错误:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Key')VALUES ('Modern_Mo', '349692657221500938', '505375472646094868', '48783440' at line 1

任何帮助都太好了!所有这些输入都是字符串,“key”指定为“modern”)

wsxa1bj1

wsxa1bj11#

KEY 是mysql中的保留字。当用作标识符时,必须在查询中引用它:

add = ("INSERT INTO server_stats_servers (Owner, ServerID, MessageID, "
       "Channel, ServerIP, ServerPort, ServerName, DiscordName, `Key`) "
       "VALUES (%(Owner)s, %(ServerID)s, %(MessageID)s, %(Channel)s, "             
       "%(ServerIP)s, %(ServerPort)s, %(ServerName)s, %(DiscordName)s, %(Key)s)")

相关问题