Home > Database > Mysql Tutorial > body text

Why Can\'t I Create the `aquaticstar.link` Table in MySQL (Error 121)?

DDD
Release: 2024-11-27 07:11:13
Original
987 people have browsed it

Why Can't I Create the `aquaticstar.link` Table in MySQL (Error 121)?

SQL Error: Unable to Create Table 'aquaticstar.link': Error 1005

The SQL script provided attempts to create a database table named 'aquaticstar.link' but encounters an error with the message "Can't create table 'aquaticstar.link' (errno: 121)."

Possible Causes:

Foreign key constraint violation: The error message indicates that the table 'link' could not be created due to a foreign key constraint issue. A constraint with the same name may already exist in another table.

Resolution:

  1. Check Existing Constraints: Run the following query to identify existing foreign key constraints:
SELECT
    constraint_name,
    table_name
FROM
    information_schema.table_constraints
WHERE
    constraint_type = 'FOREIGN KEY'
AND table_schema = DATABASE()
ORDER BY
    constraint_name;
Copy after login
  1. Identify the Duplicate Constraint: If a constraint with the same name as the one in the 'link' table is found, remove it or rename the constraint in the 'link' table.
  2. Ensure Proper Referential Integrity: Verify that the foreign key in the 'link' table refers to an existing primary key in the referenced table. Ensure that the data types and cardinality of the columns involved in the foreign key relationship are compatible.
  3. Recreate the Table: Once the constraint issue is resolved, attempt to recreate the 'link' table using the original script.

Additional Notes:

  • The error code 121 typically signifies a constraint violation or a table creation issue.
  • Ensure that the database schema is valid and all tables and relationships are correctly defined.
  • If the issue persists, inspect the database logs or contact the MySQL support team for further assistance.

The above is the detailed content of Why Can\'t I Create the `aquaticstar.link` Table in MySQL (Error 121)?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template