sqlite3.OperationalError:在“ BatchID”附近:语法错误

时间:2019-11-14 17:42:32

标签: sql sqlite

为什么我收到错误“ sqlite3.OperationalError:在“ BatchID”附近:语法错误”?

cursor.execute('''CREATE TABLE IF NOT EXISTS OrderBatch(
                    OrderBatchID INTEGER PRIMARY KEY,
                    Quantity INTEGER,
                    OrderID INTEGER,
                    FOREIGN KEY (OrderID) REFERENCES OrderTable(OrderID),
                    BatchID INTEGER,
                    FOREIGN KEY (BatchID) REFERENCES Batch(BatchID)
                    )''')

1 个答案:

答案 0 :(得分:0)

在语句末尾移动外键的定义。

CREATE TABLE IF NOT EXISTS OrderBatch(
                    OrderBatchID INTEGER PRIMARY KEY,
                    Quantity INTEGER,
                    OrderID INTEGER,
                    BatchID INTEGER,
                    FOREIGN KEY (OrderID) REFERENCES OrderTable(OrderID),
                    FOREIGN KEY (BatchID) REFERENCES Batch(BatchID)
                    )