Error: '1064 (42000): You have an error in your SQL syntax
Error: '1064 (42000): You have an error in your SQL syntax
我在 Python 中使用 MYSQL 编写代码来创建数据库配方。我写了一些变量来创建不同的表。可以创建所有,但导致错误的除外:
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 行开始。
我还假设这个变量导致了这个错误,因为当我删除它时,错误消失了,但我可能错了。
感谢您的宝贵时间:)
我想您错过了语句末尾的 )
。尝试:
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));
"""
我在 Python 中使用 MYSQL 编写代码来创建数据库配方。我写了一些变量来创建不同的表。可以创建所有,但导致错误的除外:
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 行开始。
我还假设这个变量导致了这个错误,因为当我删除它时,错误消失了,但我可能错了。
感谢您的宝贵时间:)
我想您错过了语句末尾的 )
。尝试:
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));
"""