[英]How to fix 'django.db.utils.OperationalError: near “None”: syntax error' db.sqlite3?
[英]How to fix "near ")": syntax error" in sqlite
我正在使用 Python 和 SQLite。 我不斷收到這條消息
“接近”)”:語法錯誤”。
我嘗試在所有查詢中添加分號,但仍然收到此錯誤消息。
tables.append("""
CREATE TABLE IF NOT EXISTS payment (
p_id integer PRIMARY KEY,
o_id integer NON NULL,
FOREIGN KEY(o_id) REFERENCES orders(o_id),
);"""
)
在最后的結尾之前有一個逗號) 。 只需將其刪除。
即使用:-
tables.append("""
CREATE TABLE IF NOT EXISTS payment (
p_id integer PRIMARY KEY,
o_id integer NON NULL,
FOREIGN KEY(o_id) REFERENCES orders(o_id)
);"""
)
去掉FOREIGN KEY(o_id) REFERENCES orders(o_id),
末尾的逗號FOREIGN KEY(o_id) REFERENCES orders(o_id),
工作代碼將是:
tables.append("""
CREATE TABLE IF NOT EXISTS payment (
p_id integer PRIMARY KEY,
o_id integer NON NULL,
FOREIGN KEY(o_id) REFERENCES orders(o_id)
);"""
)
嘗試這個:
tables = []
tables.append("""
CREATE TABLE IF NOT EXISTS payment p_id integer PRIMARY KEY,
o_id integer NON NULL FOREIGN KEY(o_id) REFERENCES orders(o_id),
""")
print(tables)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.