2017-03-03 109 views
0

我试图做一个名为'outfield'的表中的INSERT,它由以下字段组成:outfieldplayerID(自动递增和PK) ,姓,名,团队,游戏玩过,游戏开始,出场时间,进球,助攻,射门,射门,黄牌,射门红牌得到这个错误“1064(42000):你的SQL语法错误”

我的代码如下:

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() 

我在INSERT行中出现语法错误。我哪里错了?在列名

回答

0

使用反引号的``而不是单引号''

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') 

此外,最好在这样你就不需要在所有使用的反引号的方式来定义的标识符。

+0

问题解决了。非常感谢,谢谢 – hoops9682

相关问题