Mysql create constraint foreign key faild.trouble shooting method share
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql create constraint foreign key faild.trouble shooting method share相关的知识,希望对你有一定的参考价值。
mysql> create table tb_test (id int(10) not null auto_increment primary key,action_id int(10) not null,error_code int(10) not null default 0,desc_key varchar(64) not null default ‘audit.log.default‘,INDEX(action_id),constraint `FK_ACTIONID` foreign key(`action_id`) references `tb_tab1` (`action_id`));
ERROR 1215 (HY000): Cannot add foreign key constraint
mysql>
定位方法如下:
SHOW ENGINE INNODB STATUS:
LATEST FOREIGN KEY ERROR
------------------------
2016-01-29 08:45:15 7f5b11b09700 Error in foreign key constraint of table auditdb/tb_test:
foreign key(`action_id`) references `tb_tab1` (`action_id`)):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
很详细
以上是关于Mysql create constraint foreign key faild.trouble shooting method share的主要内容,如果未能解决你的问题,请参考以下文章
Cannot add or update a child row a foreign key constraint f
mysql执行带外键的sql文件时出现mysql ERROR 1215 (HY000): Cannot add foreign key constraint的解决
在 CREATE TABLE 的末尾添加 DEFAULT CONSTRAINT
sql [CREATE TABLE]创建一个新表,其中指定了列但没有内容,还有Constraints #SQL
ALTER TABLE CREATE CONSTRAINT IF NOT EXIST 可能吗?
SQL CREATE TABLE 语句SQL 约束 (Constraints)SQL NOT NULL 约束SQL UNIQUE 约束