为什么我收到错误“ 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)
)''')
答案 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)
)