简体   繁体   English

Python sqlite3创建表语法错误

[英]Python sqlite3 create table syntax error

Whenever I try to create a table using python and sqlite3, it gives me the following error: 每当我尝试使用python和sqlite3创建表时,都会出现以下错误:

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 我正在使用python 2.7并尝试将csv电子表格导入sqlite3

Thanks in advance EDIT: I've tried the code without the trailing comma and it still doesn't work... 在此先感谢EDIT:我已经尝试了不带逗号的代码,但仍然无法使用...

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 . 我看到您有一列称为primary
You will want to put backticks around it or rename it because it is a keyword in SQLite ; 您将需要在其周围加上反引号或对其进行重命名,因为它是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 ... . 示例中缺少) ,并且由于SQL中存在错误,因此您可能应该包含实际的execute语句,而不是...

But i'd say your error is a trailing , at the end of the list of your columns. 但是我要说的是,您的错误是在列列表末尾的结尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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