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&page=Status&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)
精彩评论