i creating table called fac_master has foreign key refers dept_id of dept_master. table getting created foreign key not getting enforced on table. have foreign key in dept_master works not table.
create table dept_master ( dept_id smallint unsigned auto_increment not null comment 'department/branch id', dept_name varchar(100) not null comment 'department name such computer engineering', prog_id tinyint unsigned not null comment 'program id under department falls', primary key(dept_id), constraint fk_dept foreign key(prog_id) references prog_master(prog_id) on delete restrict on update restrict ) engine=innodb collate latin1_general_ci; create table fac_master ( fac_id smallint unsigned auto_increment not null comment 'faculty id', dept_id smallint unsigned not null comment 'department id of department in faculty works', fac_name varchar(30) not null comment 'name of faculty', fac_father_name varchar(30) comment 'father\'s name of faculty', fac_surname varchar(30) comment 'surname of faculty', fac_designation varchar(30) not null comment 'designation of faculty', fac_mail_id varchar(50) comment 'e-mail id of faculty', fac_mobile bigint(10) unsigned comment 'mobile number of faculty', fac_address varchar(100) comment 'permanent address of faculty', fac_status varchar(1) not null comment 'status of faculty: a=active d=deactive', fac_joining_date date comment 'joining date of faculty', primary key(fac_id), constraint fk_faculty foreign key(dept_id) references dept_master(dept_id) on delete restrict on update restrict ) engine=innodb collate latin1_general_ci;
when try add value in "prog_id" of "dept_master" not present in "prog_id" of "prog_master" gives fk constraint error fine when try add value in "dept_id" of "fac_master" not present in "dept_id" of "dept_master" gets added should have given fk constraint error. checked foreign key constraint in information schema , found foreign key constraint not there table fac_master. using wamp server 2.2 on windows 7 hp 64 bit version.
what problem? please help..
edit:
alter table fac_master add constraint fk_faculty foreign key(dept_id) references dept_master(dept_id) on delete restrict on update restrict;
using alter table shown above works not when used create table. reason it?
it appears problem caused way escape '
in 'father\'s name of faculty'
. when change in 'father''s name of faculty'
, you'll find foreign key constraints correctly created.
both ways of including single quote correct according manual, bug. see this mysql bug ticket.
Comments
Post a Comment