0

I have three tables: advocate, client and event. In event table, I have two fields that are referencing two fields from advocate table and one field referencing client, and when I try to add foreign key I get this cannot add foreign key constraint error.

create table advocate(

ida int(11) not null, 
idk int(11) not null,

#...

primary key(ida, idk)

)engine = InnoDB default charset=utf8;



create table client(

jmb varchar(13) not null primary key

#...

)engine=InnoDB default charset=utf8;



create table event(

ida int(11) not null,
idk int(11) not null,
jmb varchar(13) not null,

#...

primary key(ida,idk,jmb),

foreign key(ida, idk)
references advocate(ida, idk)
on update cascade
on delete restrict,

foreign key(jmb)
references client.jmb
on update cascade
on delete restrict


)engine=InnoDB default charset=utf8;
bliny
  • 67
  • 6

1 Answers1

1

Can you try changing:

foreign key(jmb)
references client.jmb
on update cascade
on delete restrict

to

foreign key(jmb)
references client (jmb)
on update cascade
on delete restrict
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102