python-3.x - 简单表创建中的 Python sqlite3 OperationalError
问题描述
这是代码
def __init__(self):
self._db = sqlite3.connect("Reservation.db")
self._db.row_factory = sqlite3.Row
self._db.execute("create table if not exists Ticket(ID integer primary key autoincrement, Name text, Gender text, Order text)")#create a table called Ticket with 4 columns
self._db.commit()
问题
self._db.execute("如果不存在则创建表 Ticket(ID 整数主键自动增量,名称文本,性别文本,订单文本)") sqlite3.OperationalError: near "Order": 语法错误
解决方案
order
是 SQL 中的保留字。我建议您找到一个不同的名称,它不是order_text
该列的保留字(例如,)。如果您绝对必须使用此名称,您可以通过用双引号 ( ) 将其转义"
:
self._db.execute("create table if not exists Ticket(ID integer primary key autoincrement, Name text, Gender text, \"Order\" text)
# Here -----------------------------------------------------------------------------------------------------------^------^
推荐阅读
- c# - 如何在 NET Core 中使用泛型列表对泛型类进行 CRUD?
- python - 在 Python 3 中制作一个简单的“加载栏”
- android - 如何使用 SAF 从树 URI 路径访问目录及其文件
- cognos - Event Studio 对象在 Cognos 服务器上的位置
- git - 如何从提出拉取请求的源分支提取到当前分支?
- reactjs - 无法在表单提交回调/Shopify Polaris React 组件中获取更新值
- c++ - C++ 模板类 - 继承调用错误的函数
- amazon-web-services - Google Domains 和 AWS Route 53 和 S3 静态 Web 托管 - 添加 SSL 证书
- git - Git - 在远程服务器上的不同分支之间切换
- python - 在 Pandas 中,创建一个相对于组内特定类别的变量