开发者

Python sqlite3 create table syntax error

开发者 https://www.devze.com 2023-03-25 15:59 出处:网络
Whenever I try to create a table using python and sqlite3, it gives me the following error: Traceback (most recent call last)

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 开发者_JAVA技巧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; e.g.:

...
`Primary` TEXT,
...


You have a trailing "," before the closing parenthesis.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消