MySQL Error 150 during CREATE TABLE

I have one table named tbl_groupmastercreated using 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 create another table with the name tbl_groupmanagerusing the foreign key relation:

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 get this error:

SQL error: cannot create table. \ student \ tbl_groupmanager.frm '(errno: 150) ..

What is it? I can not determine my mistake. Please help me solve this problem. Thanks in advance.

+3
source share
3 answers

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

+3
source

, MyISAM - , , tbl_groupmaster - MyISAM.

MyISAM .

0

Your foreign key is not the same data type as the primary key. One of them is unsigned, one is not.

0
source

Source: https://habr.com/ru/post/1722094/


All Articles