gpt4 book ai didi

MYSQL - 无法创建外键

转载 作者:行者123 更新时间:2023-11-29 09:21:12 28 4
gpt4 key购买 nike

当我执行以下查询时,它会抛出错误,

alter table `ttis`.`users` 
add constraint `FK_Role_ID` FOREIGN KEY (`ROLE_ID`) REFERENCES `roles` (`ROLE_ID`)

错误:

Error Code : 1005
Can't create table 'ttis.#sql-9c_8a' (errno: 150)

最佳答案

看看这篇文章:13.6.4.4. FOREIGN KEY Constraints并搜索“150”。它在这里说:

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

If MySQL reports an error number 1005 from a CREATE TABLE statement, and the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. Similarly, if an ALTER TABLE fails and it refers to error 150, that means a foreign key definition would be incorrectly formed for the altered table. You can use SHOW ENGINE INNODB STATUS to display a detailed explanation of the most recent InnoDB foreign key error in the server.

关于MYSQL - 无法创建外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1761315/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com