Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error: '1064 (42000): You have an error in your SQL syntax

I’m coding in Python using MYSQL to create a database recipe. I have written some variables to create different tables. All could be created except one that caused an error :

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)
    """

I get this error message : 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'

By the way, I don’t know why it is said "line 9" since this variable starts at line 132 of my program.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have also assumed that this variable causes this error since, when I remove it, the error disappears, but I may be wrong.

Thank you for your time 🙂

>Solution :

I suppose you missed ) at the end of the statement. Try:

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));
    """
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading