Question

I cannot for the love of all that is holy figure out why I am getting this error:

Error: Duplicate key name 'Row_In'
SQLState:  42000
ErrorCode: 1061

When I try to create this table in 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)
);

I believe I have narrowed the problem down to the final foreign key, referencing RACE. I was able to create another table with an identical foreign key, but I cannot get it to work in this table.

Please help.

Was it helpful?

Solution

You're using the same index_name Row_In for three foreign keys.

Here is the syntax for Foreign Key definition 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]

Try this instead:

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top