0

I am not sure what is wrong with the following MySQL statements. I have created each table, but upon running the following statements I get the error:

Error Code: 1215. Cannot add foreign key constraint

MySQL statements:

/**
CREATE TABLE Episodes (
    season INT,
    num INT,
    title VARCHAR(50),
    director VARCHAR(50),
    viewers DECIMAL(2, 1),
    PRIMARY KEY (season, num)
);

CREATE TABLE Characters (
    name VARCHAR(50),
    house VARCHAR(50),
    PRIMARY KEY (name)
);
**/
CREATE TABLE Appearances (
    name VARCHAR(50),
    season VARCHAR(50),
    num INT,
    PRIMARY KEY (name, season, num),
    FOREIGN KEY (name) REFERENCES Characters(name),
    FOREIGN KEY (season) REFERENCES Episodes(season)
);

What am I doing wrong here?

KED
  • 183
  • 1
  • 6

1 Answers1

0

Silly error, I have an inconsistency with types for season. Changing season to have type INT fixed this error.

KED
  • 183
  • 1
  • 6