我正在使用 MYSQL 在 Python 中編碼以創建資料庫配方。我撰寫了一些變數來創建不同的表。除了導致錯誤的一個之外,所有都可以創建:
create_recipe_ingredient_table = """
CREATE TABLE IF NOT EXISTS recipe_ingredient (
recipe_ingredient_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
amount INT,
recipe_id INT,
ingredient_id INT,
measure_id INT,
FOREIGN KEY (recipe_id) REFERENCES recipe(recipe_id),
FOREIGN KEY (ingredient_id) REFERENCES ingredient(ingredient_id),
FOREIGN KEY (measure_id) REFERENCES measure(measure_id)
"""
我收到此錯誤訊息: Error: '1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 9'
順便說一句,我不知道為什么說“第 9 行”,因為這個變數從我程式的第 132 行開始。
我還假設這個變數會導致這個錯誤,因為當我洗掉它時,錯誤就會消失,但我可能是錯的。
感謝您的時間 :)
uj5u.com熱心網友回復:
我想你錯過)了宣告的結尾。嘗試:
create_recipe_ingredient_table = """
CREATE TABLE IF NOT EXISTS recipe_ingredient (
recipe_ingredient_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
amount INT,
recipe_id INT,
ingredient_id INT,
measure_id INT,
FOREIGN KEY (recipe_id) REFERENCES recipe(recipe_id),
FOREIGN KEY (ingredient_id) REFERENCES ingredient(ingredient_id),
FOREIGN KEY (measure_id) REFERENCES measure(measure_id));
"""
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/395393.html
