Dear Steve!
You must set the column address_id as primary key in the table person_address. That
should solve your problem.
Generally table, you want to join with foreign key, should have primary key. The primary
key should include the column that you use for the foreign key. Also, you should have an
index on the table including this column. This column should be the first in the index.
If the primary key is equal with this column, you must not create an index.
Hope this will help you.
Regards
Bela, Kocsis
-----Original Message-----
From: steven.p.long@stripped [mailto:steven.p.long@stripped]
Sent: Sunday, December 05, 2004 2:42 PM
To: mysql@stripped
Subject: Foreign Key Error 1005:150
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
---------------------------------------------------------------------------------------------------
Ez az elektronikus üzenet és minden csatolt file bizalmas
információt tartalmaz, kizárólag a címzett/ek
részére, így ha valamilyen hiba folytán téves helyre
érkezne meg, kérjük törölje az üzenetet. Ilyen esetben
nem jogosult az elektronikus üzenetet és a csatolt file-okat bármilyen
módon felhasználni, nem teheti közzé és nem
másolhatjak le azokat.
Valamennyi elektronikus üzenet, amelyet a dm Kft-hez, vagy annak
munkavállalójához címeztek, vagy onnan küldtek,
üzleti jellegűnek tekintendő. Ennek megfelelően az üzenet küldője vagy
címzettje hozzájárul ahhoz, hogy az dm Kft. másik, az eredeti
címzettől vagy küldőtől eltérő vezetője vagy alkalmazottja
által az üzenet megismerhető legyen annak érdekében, hogy a dm
Kft. tevékenységének folyamatossága és felügyelete
biztosítható legyen.
A dm Kft. nem vállal felelősséget az információk
hibátlan és teljes közvetítéséért, illetve
az elektronikus üzenet vírusmentességéért.
Azon elektronikus üzenetek tartalma, amelyek nem vonatkoznak a dm Kft. üzleti
működésére, a dm Kft. hivatalos működése
körében sem kiadásra sem jóváhagyásra nem
kerültek.
---------------------------------------------------------------------------------------------------