List:General Discussion« Previous MessageNext Message »
From:steven.p.long Date:December 5 2004 1:42pm
Subject:Foreign Key Error 1005:150
View as plain text  
I am unable to define a foreign key with the following three tables.  I am unable to find
the error having searched the documentation and tried several variations.  

Note that I created the first two tables with and without the index clause in the table
ddl with no difference in outcome.

The three tables and the first foreign key, person_person_address_FK1, create properly. 
The second foreign key, address_person_address_FK1, causes the error.

Please help.

create table person (
   person_id int unsigned not null auto_increment,
   constraint person_pk primary key (person_id),
   index(person_id));

create table address (
   address_id int unsigned not null auto_increment,
   constraint address_pk primary key (address_id),
   index(address_id));

create table person_address (
   person_id int unsigned not null,
   address_id int unsigned not null);

-- This statement works.
alter table person_address
 add constraint person_person_address_FK1 
foreign key (person_id) references person (person_id); 

-- This statement fails.
alter table person_address
 add constraint address_person_address_FK1 
foreign key (address_id) references address (address_id); 

Replies may be sent to slong@stripped

Thank you!

Steve
Thread
Foreign Key Error 1005:150steven.p.long5 Dec
  • Re: Foreign Key Error 1005:150Michael Stassen6 Dec
  • mysql 5.0.2-alpha-ntElim Qiu6 Dec
  • Server Configuration HelpManojSW6 Dec
  • wanted: back up scriptElim Qiu6 Dec
Re: Foreign Key Error 1005:150Heikki Tuuri6 Dec
Re: Foreign Key Error 1005:150steven.p.long6 Dec
RE: Server Configuration HelpMechain Marc6 Dec
RE: Foreign Key Error 1005:150Bela Kocsis6 Dec
RE: wanted: back up scriptDathan Pattishall6 Dec
Re: Foreign Key Error 1005:150Heikki Tuuri6 Dec