Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL error 150 during CREATE TABLE

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.

like image 237
Senthil Avatar asked Sep 25 '26 02:09

Senthil


1 Answers

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.

like image 84
David Espart Avatar answered Sep 27 '26 08:09

David Espart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!