得到此错误 "1064 (42000): SQL语法中有错误"

2024-10-01 15:40:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在我的表中插入一个名为“外场”的插入,它由以下字段组成:outfieldpayerid(自动递增和PK)、姓氏、名字、团队、已玩游戏、游戏开始、已玩分钟、进球、助攻、投篮、射门、红牌

我的代码如下:

import mysql.connector

conn = mysql.connector.connect(user='root',password ="password5",host='localhost',database='performance')
query = "INSERT INTO outfield ('Surname', 'Forename', 'Team', 'Games Played', 'Games Started', 'Minutes Played', 'Goals', 'Assists', 'Shots', 'Shots on goal', 'Yellow cards', 'Red cards') values('a','b','c','1','1','1','1','1','1','1','1','1')"

cursor = conn.cursor()
cursor.execute(query)
conn.commit()
rows = cursor.fetchall()
cursor.close()
conn.close()

我在插入行中得到一个语法错误。我哪里出错了?在


Tags: closeconnectormysqlconnquery名字cursorgames
1条回答
网友
1楼 · 发布于 2024-10-01 15:40:42

在列名中使用反撇号``而不是单引号''

insert into outfield (`Surname`, `Forename`, `Team`, `Games Played`, `Games Started`, `Minutes Played`, `Goals`, `Assists`, `Shots`, `Shots on goal`, `Yellow cards`, `Red cards`)
values ('a', 'b', 'c', '1', '1', '1', '1', '1', '1', '1', '1', '1')

另外,最好以一种根本不需要使用反勾号的方式定义标识符。在

相关问题 更多 >

    热门问题