运行生气了语句:
CREATE TABLE net_ippoolexludesection
(sectionId
int(11) NOT NULL AUTO_INCREMENT,ippoolId
int(11) NOT NULL COMMENT '地址池ID',routeId
int(11) NOT NULL COMMENT '设备ID',startip
varchar(15) NOT NULL COMMENT '起始地址',endip
varchar(15) NOT NULL COMMENT '结束地址',lstartip
bigint(255) NOT NULL COMMENT '其实IP',lendip
bigint(255) NOT NULL COMMENT '结束IP',
PRIMARY KEY (sectionId
),
CONSTRAINT net_ippoolexludesection_ibfk_1
FOREIGN KEY (ippoolId
) REFERENCES net_ippoolinfo
(poolid
) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='ip地址池排除地址段';
报错 Err] 1215 - Cannot add foreign key constraint
net_ippoolinfo 表的结构如下
CREATE TABLE net_ippoolinfo
(poolid
int(7) NOT NULL AUTO_INCREMENT,poolName
varchar(50) NOT NULL,routid
int(11) NOT NULL,gateway
varchar(15) DEFAULT NULL,maskStr
varchar(15) DEFAULT NULL,dnsip
varchar(50) DEFAULT NULL,poolSection
varchar(200) DEFAULT NULL,vpnName
varchar(50) DEFAULT NULL,maxUseNum
int(7) DEFAULT NULL,produceTime
datetime DEFAULT NULL,poolDomain
varchar(255) DEFAULT NULL,poolDomain1
varchar(255) DEFAULT NULL,
PRIMARY KEY (poolid
),
UNIQUE KEY dd
(poolid
)
) ENGINE=InnoDB AUTO_INCREMENT=220 DEFAULT CHARSET=utf8;
mysql 版本 5.6
就大神指教,
可能的原因:
1.没有使用 InnoDB as the engine on all tables.
2.你想在目标表上引用一个不存在的键。确保它是另一个表中的一个键 (it can be a primary or unique key)
3.列的类型是不一样的 (exception is the column on the referencing table can be nullable).
4.ON DELETE SET NULL is not defined to be null。所以确保列设置默认为空。