我不能因为所有神圣的爱而弄清楚为什么我会收到这个错误:
Error: Duplicate key name 'Row_In' SQLState: 42000 ErrorCode: 1061
当我尝试在MySQL中创建此表时:
CREATE TABLE Row_In(
Rower_Email VARCHAR(25) NOT NULL,
Boat_Name VARCHAR(25) NOT NULL,
Race_time TIME NOT NULL,
Reg_name VARCHAR(25) NOT NULL,
Reg_Date DATE NOT NULL,
Rower_Position ENUM('1','2','3','4','5','6','7','8', 'C') NOT NULL,
Boat_College VARCHAR(25) NOT NULL,
Boat_Gender ENUM('M','W') NOT NULL,
PRIMARY KEY (Rower_Email, Boat_Name, Race_Time, Reg_Name, Reg_Date, Rower_Position, Boat_College, Boat_Gender),
FOREIGN KEY Row_In(Rower_Email) REFERENCES User(Primary_Email),
FOREIGN KEY Row_In(Boat_Name, Boat_Gender, Boat_College) REFERENCES BOAT(Name, Team_Gender, Team_College),
FOREIGN KEY Row_In(Race_time, Reg_name ,Reg_Date) REFERENCES RACE(Race_Time, Reg_Name, Reg_Date)
);
我相信我已经将问题缩小到最终的外键,引用了RACE。我能够使用相同的外键创建另一个表,但我无法在此表中使用它。
请帮忙。
答案 0 :(得分:2)
您对三个外键使用相同的 index_name Row_In
。
以下是MySQL中外键定义的语法:
[CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name, ...)
REFERENCES tbl_name (index_col_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option]
请改为尝试:
FOREIGN KEY (Rower_Email)
REFERENCES User(Primary_Email),
FOREIGN KEY (Boat_Name, Boat_Gender, Boat_College)
REFERENCES BOAT(Name, Team_Gender, Team_College),
FOREIGN KEY (Race_time, Reg_name ,Reg_Date)
REFERENCES RACE(Race_Time, Reg_Name, Reg_Date)