php - #1215 - Cannot add foreign key constraint -


alter table `attendance`   add constraint `attendance_ibfk_1` foreign key (`subid`) references `subject` (`subid`) on delete cascade on update cascade,   add constraint `attendance_ibfk_2` foreign key (`studid`) references `studentdetails` (`studid`) on delete cascade on update cascade;  --attendance table  create table if not exists `attendance` (   `attid` bigint(4) not null auto_increment,   `studid` varchar(20) not null,   `subid` bigint(4) not null,   `totalclasses` int(2) not null,   `attendedclasses` int(2) not null,   `percentage` double(4,2) not null,   `comment` text not null,   primary key (`attid`),   key `studid` (`studid`),   key `subid` (`subid`) ) engine=innodb  default charset=latin1 auto_increment=7 ;  --subject table is...  create table if not exists `subject` (   `subid` bigint(4) not null auto_increment,   `subname` varchar(20) not null,   `courseid` bigint(4) not null,   `lecid` bigint(4) not null,   `subtype` varchar(25) not null,   `semester` varchar(25) not null,   `comment` text not null,   primary key (`subid`),   key `courseid` (`courseid`) ) engine=innodb  default charset=latin1 auto_increment=8 ;  -- table structure table `studentdetails` --  create table if not exists `studentdetails` (   `studid` varchar(25) not null,   `studfname` varchar(20) not null,   `studlname` varchar(20) not null,   `fathername` varchar(25) not null,   `gender` varchar(20) not null,   `address` varchar(100) not null,   `contactno` varchar(20) not null,   `courseid` bigint(4) not null,   `semester` varchar(20) not null,   `dob` date not null,   primary key (`studid`),   key `courseid` (`courseid`) ) engine=innodb default charset=latin1; 

there type mismatch. attendance.studid varchar(20) studentdetails.studid varchar(25)

i guess both should varchar(20) or varchar(25).


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -