-2

I have a syntax error I'm having trouble discerning. Help appreciated!

Schema Creation Failed: 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 '`i_id` int, PRIMARY KEY (d_id), FOREIGN KEY (i_id) REFERENCES Indicators (i_id' at line 6:

CREATE TABLE Indicators
(
    `i_id` int AUTO_INCREMENT,
    `i_name` varchar(255),
    PRIMARY KEY (i_id)
);

CREATE TABLE Data
(
    `d_id` int AUTO_INCREMENT,
    `Year` year,
    `Datapoint` float(24,2)
    `i_id` int,
    PRIMARY KEY (d_id),
    FOREIGN KEY (i_id) REFERENCES Indicators (i_id)
);
4

2 に答える 2

6

Datapoint行末のカンマがありません

また、MySQL インスタンスのデフォルト エンジンがそうでないInnoDB場合、外部キーを作成できません。

于 2013-05-31T20:00:49.903 に答える
2
CREATE TABLE Data
(
    `d_id` int AUTO_INCREMENT,
    `Year` year,
    `Datapoint` float(24,2),
                           ^------ here it is
    `i_id` int,
    PRIMARY KEY (d_id),
    FOREIGN KEY (i_id) REFERENCES Indicators (i_id)
);

後にカンマがありませんfloat(24,2)

于 2013-05-31T20:01:11.423 に答える