无法在 mysql 表上创建外键
当我尝试此操作时
ALTER TABLE Comp_Entry
ADD FOREIGN KEY(CompetitionID) REFERENCES Comp__Competition(CompetitionID)
,出现此错误
#1005 - Can't create table 'chris_db.#sql-1464b_66' (errno: 150) (<a href="server_engines.php?engine=InnoDB&page=Status&token=7a7f690fbd1413e74979d79fa9044fb0">Details...</a>)
我的 Comp_Competition
表将 CompetitionID
设置为主键。有人熟悉这个问题吗?
When I try this
ALTER TABLE Comp_Entry
ADD FOREIGN KEY(CompetitionID) REFERENCES Comp__Competition(CompetitionID)
I get this error
#1005 - Can't create table 'chris_db.#sql-1464b_66' (errno: 150) (<a href="server_engines.php?engine=InnoDB&page=Status&token=7a7f690fbd1413e74979d79fa9044fb0">Details...</a>)
My Comp_Competition
table has CompetitionID
set as the primary key. Is anyone familiar with this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 Comp_Entry 表需要一个现有的 ComparisonID 索引。另外,您的命令在表 Comp__Competition 的名称中有两个
__
字符,但在您的解释中只有一个。哪一个是正确的?Your Comp_Entry table needs an existing index for CompetitionID. Also, your command has a double
__
characters in the name for table Comp__Competition, but in your explanation you have only one. Which one is right?因为表中的数据不符合您的约束(例如不存在的键),
请尝试使
Because there is data in your table which does not feet to your constraint (for example nonexistent keys)
try to make