【发布时间】:2021-12-27 20:11:39
【问题描述】:
我正在使用 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 行开始。
我还假设这个变量会导致这个错误,因为当我删除它时,错误消失了,但我可能错了。
感谢您的宝贵时间:)
【问题讨论】:
标签: python mysql sql database mysql-python