开发者

Can't create foreign key on mysql table

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&amp;page=Status&amp;token=7a7f690fbd1413e74979d79fa9044fb0">Details...</a>)

My Comp_Competitio开发者_运维问答n table has CompetitionID set as the primary key. Is anyone familiar with this problem?


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

     select * from Comp_Entry where CompetitionID not in 
        (select distinct CompetitionID from Comp__Competition)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜