我收到错误消息:
Traceback (most recent call last): File "./CREATE.py", line 13, in **cur.execute("CREATE TABLE IF NOT EXISTS Test(Id INT PRIMARY KEY AUTO_INCREMENT, FirstName VARCHAR(25), LastName VARCHAR(25), Email VARCHAR (25), FlightNo. INT)")** File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute self.errorhandler(self, exc, value) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue **_mysql_exceptions.ProgrammingError: (1064, "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 'INT)' at line 1")**
我很困惑,不知道我需要改变什么。任何人都可以协助。用于创建表的python脚本如下所示。
#!/usr/bin/python
#! -*- coding: utf-8 -*-
import MySQLdb as mdb
con = mdb.connect('localhost', 'root', 'Team3', 'TestDB');
with con:
cur = con.cursor()
cur.execute("SET sql_notes = 0; ")
#cur.execute("DROP TABLE IF EXISTS Test")
cur.execute("CREATE TABLE IF NOT EXISTS Test(Id INT PRIMARY KEY AUTO_INCREMENT, FirstName VARCHAR(25), LastName VARCHAR(25), Email VARCHAR (25), FlightNo. INT)")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Jim', 'Bo','JIMBO@email.com, '2829922')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlighNo.) VALUES('Kevin', 'Wilkinison', 'KevinWilkinson@email.com', '3773827')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Osei', 'Seraphin','OseiSeraphin@email.com', '8171882')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Nicholas', 'Alexander', 'NicholasAlexander@email.com', '2625554')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Lejaney', 'Blue', 'LejaneyBlue@email.com', '0099884')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Brandon', 'Crandall', 'BrandonCrandall@email.com', '8833736')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Lola', 'Obasa', 'LolaObasa@email.com', '6657588')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Bob', 'Pizza', 'BobPizza@email.com', '3938722')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('John', 'Doe', 'JohnDoe@email.com', '3345223')")
cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Lisa', 'Ray', 'LisaRay@email.com', '7677584')")
答案 0 :(得分:1)
你的字符串
"CREATE TABLE IF NOT EXISTS Test(Id INT PRIMARY KEY AUTO_INCREMENT, FirstName VARCHAR(25), LastName VARCHAR(25), Email VARCHAR (25), FlightNo. INT)"
CREATE TABLE IF NOT EXISTS Test
(Id INT PRIMARY KEY AUTO_INCREMENT,
FirstName VARCHAR(25),
LastName VARCHAR(25),
Email VARCHAR (25),
FlightNo. INT)
它在FlightNo之后有一段句点(。)
删除它