[Err] 1215 – Cannot add foreign key constraint求大神们解决

MySql 码拜 10年前 (2014-04-27) 770次浏览 0个评论
 

/*==============================================================*/
/* Table: H_Dict_Channel_Type      渠道类型           */
/*==============================================================*/
create table IF NOT EXISTS  H_Dict_Student_Grade
(
   Code                 varchar(20) not null,
   Name                 national varchar(50) not null,
   Memo                 national varchar(100),
   Is_Valid             bool not null,
   Creator_Code         varchar(20) not null,
   Create_Time          bigint not null,
   primary key (Code)
)ENGINE=InnoDB DEFAULT CHARSET=gbk;

/*==============================================================*/
/* Table: H_Dict_Channel_Source      渠道来源         */
/*==============================================================*/
create table IF NOT EXISTS  H_Dict_Channel_Source
(
   Code                 varchar(20) not null,
 Channel_Type_Code varchar(20) not null,
   Name                 national varchar(50) not null,
   Memo                 national varchar(100),
   Is_Valid             bool not null,
   Creator_Code         varchar(20) not null,
   Create_Time          bigint not null,
   primary key (Code)
)ENGINE=InnoDB DEFAULT CHARSET=gbk;

alter table  H_Dict_Channel_Source add constraint FK_H_Dict_Channel_Source_FK_A foreign key
(Channel_Type_Code)
      references H_Dict_Channel_Type
(Code);

[Err] 1215 – Cannot add foreign key constraint

程序报错,大神们帮忙看下

….找到问题了,表明错了
40分
alter table  H_Dict_Channel_Source add constraint FK_H_Dict_Channel_Source_FK_A foreign key
(Channel_Type_Code)
      references H_Dict_Channel_Type
(Code);
你的这个表根本没有创建。

mysql> create table H_Dict_Channel_Type (Code varchar(20) primary key)ENGINE=Inn
oDB DEFAULT CHARSET=gbk;
Query OK, 0 rows affected (0.05 sec)

mysql> create table IF NOT EXISTS  H_Dict_Channel_Source
    -> (
    ->    Code                 varchar(20) not null,
    ->  Channel_Type_Code       varchar(20) not null,
    ->    Name                 national varchar(50) not null,
    ->    Memo                 national varchar(100),
    ->    Is_Valid             bool not null,
    ->    Creator_Code         varchar(20) not null,
    ->    Create_Time          bigint not null,
    ->    primary key (Code),
    ->    constraint FK_H_Dict_Channel_Source_FK_A foreign key
    -> (Channel_Type_Code)
    ->       references H_Dict_Channel_Type
    -> (Code)
    -> )ENGINE=InnoDB DEFAULT CHARSET=gbk;
Query OK, 0 rows affected (0.06 sec)

mysql>

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明[Err] 1215 – Cannot add foreign key constraint求大神们解决
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!