【问题标题】:Python sqlite3 OperationalError in a simple table create简单表创建中的 Python sqlite3 OperationalError
【发布时间】:2020-06-28 00:59:57
【问题描述】:

这里是代码

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:靠近“订单”:语法错误

【问题讨论】:

    标签: python-3.x sqlite


    【解决方案1】:

    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 -----------------------------------------------------------------------------------------------------------^------^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-05
      • 2015-07-30
      • 2016-02-20
      相关资源
      最近更新 更多