mysql - SQL FK constraint fails -
i have 2 tables, office , user. want make relation onetomany (1 office has many users).
but when run sql
alter table izo_user add constraint fk_da8075cffa0c224 foreign key (office_id) references izo_office (id) create index idx_da8075cffa0c224 on izo_user (office_id)
something goes wrong , error
sqlstate[23000]: integrity constraint violation: 1452 cannot add or update child row: foreign key constraint fails (`izoplast`.`#sql-9842_1be9`, constraint `fk_da8075cffa0c224` foreign key (`office_id`) references `izo_office` (`id`))
my tables: http://oi57.tinypic.com/whhezr.jpg
try if works you-
alter table izo_user add index idx_office_id(office_id); alter table izo_user add constraint fk_da8075cffa0c224 foreign key (office_id) references izo_office (id);
Comments
Post a Comment