Search code examples
mysql-error-1064

mysql 1064 error on execution


I´ve got this table:

mysql> CREATE TABLE favorite food
-> (person_id SMALLINT UNSIGNED,
->food VARCHAR(20),
->CONSTRAINT pk_favorite_food PRIMARY KEY (person_id, food),
->CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id)
->REFERENCES person (person_id)
->);

After execution i get the error 1064. Anybod any ideas what could be wrong?

MySQL Server 6.0


Solution

  • By searching some possible response on Google, I found this thread on SO... The original table (which is the same as your, but with a nicer formatting) is:

    CREATE TABLE favorite_food(
        person_id SMALLINT UNSIGNED,
        food VARCHAR(20),
        CONSTRAINT pk_favorite_food PRIMARY KEY(person_id,food),
        CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id) REFERENCES person(person_id)
    );
    
    1. You probably don't have the person table, so the foreign key can't be created. (see the last line)
    2. You have remove the _ in the table name (favorite food instead of favorite_food) which is not allowed.