Home >Database >Mysql Tutorial >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:
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:
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');
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!