Dorababu Meka

Dorababu Meka

  • 226
  • 8.3k
  • 1.7m

Error Code 1005 in mysql while applying Foreign key to a table

Oct 1 2011 1:06 AM
I am having two tables tbluserlogindetail and tblRoles.
tbluserlogindetail is as follows
CREATE TABLE `tbluserlogindetail` (
 
`ID` int(11) NOT NULL AUTO_INCREMENT,
 
`LoginID` varchar(45) NOT NULL,
 
`Name` varchar(45) DEFAULT NULL,
 
`Password` varchar(45) DEFAULT NULL,
 
PRIMARY KEY (`ID`,`LoginID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
and my second table tblRoles is as follows
CREATE TABLE `tblroles` (
 
`RoleID` int(11) NOT NULL,
 
`LoginID` varchar(45) NOT NULL,
 
PRIMARY KEY (`RoleID`,`LoginID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$
I tried the the following to assign a primary key for the column LoginID in tblroles table but i don't know where i went wrong can any one help me.
I have gone through the documentation but unable to rectify the error so please help me
ALTER TABLE tblroles ADD FOREIGN KEY (loginid) REFERENCES tbluserlogindetail(loginid)