mysql建立外來鍵報錯 Mysql表建立外來鍵報錯

2021-10-17 16:52:28 字數 1055 閱讀 8713

資料庫表a:

create table task_desc_tab

id int(11) primary key not null comment '自增主鍵' auto_increment,

taskname varchar(200) not null comment '任務名字',

sqlname varchar(20) not null comment 'sql檔案名字',

params varchar(5000) not null comment '任務引數,格式為乙個json字串',

updatetime timestamp default current_timestamp comment '更新時間',

detail varchar(3000) comment '任務一些描述資訊,只是備註資訊作用'

engine = innodb

default charset = utf8;

資料庫b:

create table exec_plan_tab

id int(11) primary key not null auto_increment,

taskname varchar(200) not null,

startdate date not null,

enddate date not null,

updatetime timestamp default current_timestamp,

constraint exec_plan_tab_task_desc_tab_taskname_fk foreign key (taskname) references task_desc_tab (taskname)

engine = innodb

default charset = utf8;

[2018-07-19 15:02:29] [hy000][1215] cannot add foreign key constraint

[2018-07-19 15:02:29] [hy000][1215] cannot add foreign key constraint

mysql 新增外來鍵報錯

父表 子表 以上,父表和的對應字段資料型別一致,排除新增的外來鍵列與另乙個表的唯一索引列 一般是主鍵 的資料型別不同這一因素。use information schema select table catalog,table schema,table name,engine from tables ...

mysql建立外來鍵

建立外來鍵的前提 本表的列必須與外來鍵型別相同 外來鍵必須是外表主鍵 外來鍵作用 使兩張表形成關聯,外來鍵只能引用外表中的列的值!指定主鍵關鍵字 foyunmkreign key 列名 引用外來鍵關鍵字 references 外來鍵表名 外來鍵列名 事件觸發限制 on delete和on updat...

mysql建立外來鍵案例 MySQL外來鍵例項

外來鍵例項 性別表create table gender gid int auto increment primary key not null,gender char 10 insert into gender gender values male female unknown 乙個表只能有乙個主...