spring - ERROR 1215 (HY000): Cannot add foreign key constraint in mysql -


hi iam creating 2 table in mysql onetoone mapping in spring hibernate,but getting error error 1215 (hy000): cannot add foreign key constraint

this first table

create table `employee` (  `empid` int(11) not null,   `empname` varchar(255) default null,  `empexp` int(11) not null,  `empteam` varchar(255) default null,  `teamid` int(11) default null); 

second table

create table `empteam` (  `teamid` int(11) not null,  `teamname` varchar(255) default     null, primary key (`teamid`)  ,  key `fk1` (`teamid`), constraint `fk1` foreign key (`teamid`)   references `employee`   (`empid`)); 

please help,thanks in advance

try this

  create table `empteam` (  `teamid` int(11) not null,                              `teamname` varchar(255) default     null,                              primary key (`teamid`)  ,                              constraint `fk1` foreign key (`teamid`)                               references `employee`   (`empid`)); 

if have fk1 remove , create again:

   alter table `empteam` drop foreign key `fk1` 

edit:

you have add primary key in employee table . , should work.

change this

   create table `employee` (  `empid` int(11) not null , 

to

   create table `employee` (  `empid` int(11) not null  primary key , 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -