在创建两个表关联时提示Can't create table './test1/configure.frm' (errno: 150),在网上看了很多文章,说修改TYPE=INNODB,然后加个INDEX就行了,可是还是行不通,大家帮我看看哪里还有问题.
p8_members表
CREATE TABLE `p8_members` (
  `uid` mediumint(7) unsigned NOT NULL auto_increment,
  `username` varchar(30) NOT NULL default '',
  `password` varchar(32) NOT NULL default '',
  PRIMARY KEY  (`uid`)
) TYPE=INNODB AUTO_INCREMENT=3 DEFAULT CHARSET=gbk;configure表
create table configure(
     ID int not null,
     user_id mediumint(7) not null,
     primary key (ID),
     index user_id (user_id),
     foreign key (user_id) references p8_members (uid)
     )TYPE=INNODB AUTO_INCREMENT=3 DEFAULT CHARSET=gbk;

解决方案 »

  1.   

    create table student 

    stu_id int primary key auto_increment, 
    stu_name varchar(20), 
    stu_sex varchar(10), 
    stu_age int, 
    stu_birthday datetime, 
    classes_id int not null,
    unique (classes_id)
    )ENGINE=INNODB; create table classes 

    classes_id int primary key , 
    classes_name varchar(20), 
    teacher_id int, 
    foreign key (classes_id) references student(classes_id) 
    )ENGINE=INNODB; 
      

  2.   

    [root@localhost ~]# perror 150
    MySQL error code 150: Foreign key constraint is incorrectly formed
      

  3.   

    终于发现问题了,原来是configure表的类型有问题,忘了加unsigned.
    但为什么一定要TYPE=INNODB才能有外键??
      

  4.   

    这是由于外键关联表格未建立,导致外键创建失败所致,只要取消外键关联的检查即可:set foreign_key_checks=0