Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

Can't create foreign key on mysql table

0

46 views

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_Competition table has CompetitionID set as the primary key. Is anyone familiar with this problem?

asked March 23, 2011 11:00 pm CDT
posted via StackOverflow

2 Answers

0
 

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?

answered March 23, 2011 11:23 pm CDT
0
 

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)

answered March 23, 2011 11:23 pm CDT

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions