Error: Can't Create Table Due to Duplicate Constraint Name
In forward engineering your MySQL database into WAMP server, you encountered the error "Error 1005: Can't create table 'aquaticstar.link' (errno: 121)." This error indicates that a table with the specified name already exists in the database.
Upon further investigation, it was discovered that the issue is related to duplicate constraint names. Specifically, the Link table contains foreign key constraints named id and lesson_id, which are also present in other tables. This naming conflict prevents the database from creating the Link table.
To resolve this problem, you should rename the foreign key constraints in the Link table to unique names. This can be achieved by modifying the following lines in the executed script:
CONSTRAINT `id` FOREIGN KEY (`id` ) REFERENCES `Students` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `lesson_id` FOREIGN KEY (`lesson_id` ) REFERENCES `Schedule` (`lesson_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;
For example, you can rename the id constraint to student_id and the lesson_id constraint to schedule_lesson_id.
CONSTRAINT `student_id` FOREIGN KEY (`id` ) REFERENCES `Students` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `schedule_lesson_id` FOREIGN KEY (`lesson_id` ) REFERENCES `Schedule` (`lesson_id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;
Once you have renamed the constraints, re-execute the script to create the Link table successfully.
The above is the detailed content of Why Can\'t I Create My MySQL Table Due to Duplicate Constraint Names?. For more information, please follow other related articles on the PHP Chinese website!