一个表purview有两个字段。relo_id和menu_id
但奇怪的是,以这两个为联合主键时。建不了此字段的外键。
到底怎么回事啊?

解决方案 »

  1.   

    MySQL 只有 innodb 类型才支持外键
      

  2.   


    mysql> create table purview ( relo_id int not null, menu_id int not null, str char(20) not null, primary key f_k (relo_id,menu_id) ) engine innodb;
    Query OK, 0 rows affected (0.00 sec)mysql> create table child (id int not null primary key, relo_id int not null, menu_id int not null, index (relo_id,menu_id), foreign key (relo_id,menu_id) references purview(relo_id,menu_id) ) engine innodb;
    Query OK, 0 rows affected (0.00 sec)mysql>