Tom Haines
Tom Haines

Reputation: 11

sqlite3.OperationalError in Python 3 when creating table

The following code shows up this error when run.

Error:

 INTEGER PRIMARY KEY LadID)""".format(usr))
 sqlite3.OperationalError: near "LadID": syntax error

Code:

c.execute("""CREATE TABLE {}
        (LadID INTEGER,
        foreName TEXT,
        surname TEXT,
        interests INTEGER,
        gender TEXT,
        mob INTEGER
        INTEGER PRIMARY KEY (LadID))""".format(usr))

What is the solution?

Upvotes: 1

Views: 449

Answers (1)

Kasravnd
Kasravnd

Reputation: 107287

Seems that you have omitted a comma after mob INTEGER also you need to change the last column to LadID INTEGER PRIMARY KEY.

Note that you should put your column name at the start of column definition and don't need to parenthesis.

c.execute("""CREATE TABLE {}
        (LadID INTEGER,
        foreName TEXT,
        surname TEXT,
        interests INTEGER,
        gender TEXT,
        mob INTEGER,
        LadID INTEGER PRIMARY KEY)""".format(usr))

Upvotes: 1

Related Questions