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:
-
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
-
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.
-
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.
-
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!