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的更多相关文章

  1. MYSQL外键(Foreign Key)的使用

    在MySQL 3.23.44版本后,InnoDB引擎类型的表支持了外键约束.外键的使用条件:1.两个表必须是InnoDB表,MyISAM表暂时不支持外键(据说以后的版本有可能支持,但至少目前不支持): ...

  2. MySQL数据库之-foreign key 外键(一对多、多对多、一对一)、修改表、复制表

    摘要: 外键 一对多 外键 多对多 外键 一对一 --------------------------------------------------------------------------- ...

  3. MySQL Foreign Key

    ntroduction to MySQL foreign key A foreign key is a field in a table that matches another field of a ...

  4. Database Primary key and Foreign key [From Internet]

    Database Primary key and Foreign key --Create Referenced Table CREATE TABLE Department ( DeptID int ...

  5. MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误

    前几天,发现从库挂了,具体报错信息如下: 分析思路 1. 因为我采用的是选择性复制,只针对以下几个库进行复制: card,upay,deal,monitor,collect.所以,不太可能出现对于sa ...

  6. MySQL添加外键时报错 ERROR 1215 (HY000): Cannot add foreign key constraint

    1.数据类型      2.数据表的引擎 数据表 mysql> show tables; +------------------+ | Tables_in_market | +--------- ...

  7. django migrate报错:1005 - Can't create table xxx (errno: 150 "Foreign key constraint is incorrectly formed")

    自从mysql升级,以及使用mariaDB以来,很多不曾更新django中model的外键, 今天,按以前的思路写完外键之后, migrate命令报错: 1005 - Can't create tab ...

  8. MySQL设置外键报错 #1452 - Cannot add or update a child row: a foreign key constraint fails 解决方法

    MySQL数据库,当我尝试在A表中设置B表的主键为外键时,报出错误:#1452 - Cannot add or update a child row: a foreign key constraint ...

  9. 【MySQL】Create table 以及 foreign key 删表顺序考究。

    1.以下是直接从数据库导出的建表语句. 1 -- ---------------------------- 2 -- Table structure for files 3 -- ---------- ...

随机推荐

  1. Python 进阶_OOP 面向对象编程_实例属性和方法

    目录 目录 构造器和解构器 构造器 __init__ 真构造器 __new__ 解构器 __del__ 实例方法 Python 中的 抽象方法 实例属性 查看实例属性 实例属性和类属性的区别 访问不可 ...

  2. Red Gate .NET Reflector

    Debug and decompile inside Visual Studio (VSPro edition) Use the Visual Studio debugger Use your reg ...

  3. 中介者模式(Mediator Pattern)

    用于减少多个对象或类之间的通信复杂性. 此模式提供了一个中介类,它通常处理不同类之间的所有通信,并支持通过松散耦合来维护代码.中介者模式属于行为模式类别. 实现实例 在这里通过一个聊天室的示例来演示中 ...

  4. 转 zookeeper,dubbo和Nginx的区别

    Nginx是著名的反向代理服务器,也被广泛的作为负载均衡服务器 ZooKeeper是分布式协调服务框架,有时也被用来做负载均衡 那么他们的区别是什么?如何选择呢? 下面从实际场景看下他们的关系 Ngi ...

  5. qq传文件测试用例设计

  6. Spring Cloud Gateway注册到服务器中心(Consul)

    Spring Cloud Gateway注册到服务器中心(Consul) 准备环境 启动Consul(./consul agent -dev)作为服务中心,默认是8500端口,然后启动spring-c ...

  7. Linux下实现客户端和服务器端的通信

    首先,可以将代码复制下来放到U盘里,然后挂载到Linux上 挂载步骤 找到设备->USB->你U盘的名字 挂载成功 访问U盘把代码拷贝到home文件夹下,就可以直接进行编译. client ...

  8. HDU2732 Leapin' Lizards

    Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. 针对类别的5中softmax_cross_entropy loss计算

    # ---------------------------- #! Copyright(C) 2019 # All right reserved. # 文件名称:xxx.py # 摘 要:五种方式实现 ...

  10. Solr是什么?

    么是Solr?Solr是什么? 答:Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口. Solr是一个高性能,采用Java开发,基于Lucene的全文搜索服 ...