1

i am getting the error message:

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")**

I am very confused and not sure what i need to change. can anyone please assist. the python script to create the table is below.

#!/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','[email protected], '2829922')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlighNo.) VALUES('Kevin', 'Wilkinison', '[email protected]', '3773827')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Osei', 'Seraphin','[email protected]', '8171882')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Nicholas', 'Alexander', '[email protected]', '2625554')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Lejaney', 'Blue', '[email protected]', '0099884')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Brandon', 'Crandall', '[email protected]', '8833736')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Lola', 'Obasa', '[email protected]', '6657588')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Bob', 'Pizza', '[email protected]', '3938722')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('John', 'Doe', '[email protected]', '3345223')")
    cur.execute("INSERT INTO Test(FirstName, LastName, Email, FlightNo.) VALUES('Lisa', 'Ray', '[email protected]', '7677584')")

1 Answer 1

1

Your string

"CREATE TABLE IF NOT EXISTS Test(Id INT PRIMARY KEY AUTO_INCREMENT, FirstName VARCHAR(25), LastName VARCHAR(25), Email VARCHAR (25), FlightNo. INT)"

It becomes (better visualized I mean)

CREATE TABLE IF NOT EXISTS Test
(Id INT PRIMARY KEY AUTO_INCREMENT, 
FirstName VARCHAR(25), 
LastName VARCHAR(25), 
Email VARCHAR (25), 
FlightNo. INT)

And it has a period (.) after FlightNo

Remove it

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @Drew, your comment was helpful. Deleting my answer.
Just thought you'd like to know @dstudeba, didn't mean to chase you away !
No worries @Drew, education is always appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.