简体   繁体   中英

Python sqlite3 create table syntax error

Whenever I try to create a table using python and sqlite3, it gives me the following error:

Traceback (most recent call last)
File "directory.py", line 14, in <module>
'Children' TEXT, 'Other' TEXT, 'Masul' TEXT);''')
sqlite3.OperationalError: near ")": syntax error

The way I'm trying to create the table is:

conn.execute('''create table Jamaat
            (id integer primary key,
            Email TEXT, 
            LastName TEXT, 
            Address1 TEXT, 
            Apt TEXT,
             Address2 TEXT, 
             City TEXT,
              State TEXT,
               Zip TEXT, 
             HomePhone TEXT,
              FaxNumber TEXT,
               Primary TEXT,
                Spouse TEXT,
             Children TEXT,
              Other TEXT,
               Masul TEXT);''')
conn.commit()          

I'm using python 2.7 and trying to import a csv spreadsheet into sqlite3

Thanks in advance EDIT: I've tried the code without the trailing comma and it still doesn't work...

Often when you get this kind of error it is because you are using keywords as column (or table) names.

I see that you have a column called primary .
You will want to put backticks around it or rename it because it is a keyword in SQLite ; eg:

...
`Primary` TEXT,
...

右括号前有一个结尾的“,”。

There's a missing ) in your sample, and since the error is in your SQL you should probably include the actual execute statement not ... .

But i'd say your error is a trailing , at the end of the list of your columns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM