Home > Database > Mysql Tutorial > Why Can\'t I Create My MySQL Table Due to Duplicate Constraint Names?

Why Can\'t I Create My MySQL Table Due to Duplicate Constraint Names?

Patricia Arquette
Release: 2024-11-26 05:15:24
Original
474 people have browsed it

Why Can't I Create My MySQL Table Due to Duplicate Constraint Names?

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;
Copy after login

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;
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template