tags:

views:

43

answers:

3

Hi all, I have one table with name tbl_groupmaster created with SQL as shown below:

create table tbl_groupmaster (
  tgm_groupid int(10) unsigned NOT NULL auto_increment,
  tgm_groupname varchar(50),
  tgm_groupdescription varchar(50),
  PRIMARY KEY (tgm_groupid)
)

and I am creating one more table with name tbl_groupmanager, using a foreign key relationship:

create table tbl_groupmanager (
  tgmgr_groupmangerid int(10) NOT NULL,
  tgm_groupid int(10),
  UserNamesID int(10),
  tgmgr_groupsize int(10),
  tgmgr_groupassigned_date datetime,
  tgmgr_grouplead_status enum ('active','inactive'),
  PRIMARY KEY (tgmgr_groupmangerid),
  FOREIGN KEY (tgm_groupid) REFERENCES tbl_groupmaster(tgm_groupid)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

But I am getting this error:

SQL Error: Can't create table '.\student\tbl_groupmanager.frm' (errno: 150)..

What is this? I am unable to identify my mistake. Please help me to resolve this. Thanks in advance.

A: 

Most probably, MyISAM is default engine in your database and hence tbl_groupmaster is MyISAM.

MyISAM does not support foreign keys.

Quassnoi
Hi, I changed into as InnoDB and then only created.. So i am sure no pbm with that.. Any other suggesstions??
Senthil
A: 

Your foreign key is not the same datatype as the primary key it references. One is unsigned, one isn't.

bobince
+3  A: 

The type of the foreign key has to be the same as the referenced key. Change tgm_groupid on table tbl_groupmanager to int(10) unsigned and it will work.

despart
Hey Thanx ...You are right.. Its worked... Great work...
Senthil
You are welcome :)
despart
Hey, remember to accept the question :)
despart