Home > Database > Mysql Tutorial > Why Can\'t I Create Table \'aquaticstar.link\'?

Why Can\'t I Create Table \'aquaticstar.link\'?

Mary-Kate Olsen
Release: 2024-11-29 20:14:14
Original
190 people have browsed it

Why Can't I Create Table 'aquaticstar.link'?

Can't Create Table 'aquaticstar.link' (errno: 121)

This error occurs when attempting to create a table with a foreign key constraint that references a non-existent table or column. In this case, the Link table contains the following foreign key constraints:

  1. FOREIGN KEY (id) REFERENCES Students (id)
  2. FOREIGN KEY (lesson_id) REFERENCES Schedule (lesson_id)

Upon closer examination of the provided SQL script, it becomes evident that the Students table and Schedule table both exist and are properly defined. However, the error message suggests that the Link table cannot be created due to an issue with one of its foreign key constraints.

To resolve this issue, ensure that the following conditions are met:

  • The Students and Schedule tables exist in the database.
  • The Students table contains a column named id that serves as the primary key.
  • The Schedule table contains a column named lesson_id that serves as the primary key.

If all these conditions are met, then the issue may lie within the SQL script itself. Double-check the spelling and syntax of the foreign key constraints in the Link table definition.

Additionally, you can try executing the following SQL query to verify the existence of the referenced tables and columns:

SELECT
    *
FROM
    INFORMATION_SCHEMA.TABLES
WHERE
    TABLE_NAME IN ('Students', 'Schedule');

SELECT
    *
FROM
    INFORMATION_SCHEMA.COLUMNS
WHERE
    TABLE_NAME IN ('Students', 'Schedule')
    AND COLUMN_NAME IN ('id', 'lesson_id');
Copy after login

If the output of these queries confirms that the required tables and columns exist, then the problem may be related to a permission issue. Ensure that the user executing the SQL script has the necessary privileges to create tables and establish foreign key relationships.

The above is the detailed content of Why Can\'t I Create Table \'aquaticstar.link\'?. 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