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. vlc 学习网

    http://capricasoftware.co.uk/#/projects/vlcj/tutorial

  2. Asp.Net Core 第07局:路由

    总目录 前言 本文介绍Asp.Net Core 路由. 环境 1.Visual Studio 2017 2.Asp.Net Core 2.2 开局 第一手:路由概述 1.路由主要用于处理特定的请求. ...

  3. Reciting(second)

      It is subtly revealed in the caricature that a son is expressing his concern about disposing of nu ...

  4. CommonJS规范 by ranyifeng

    1,概述 CommonJS是服务器端模块的规范,Node.js采用了这个规范. 根据CommonJS规范,一个单独的文件就是一个模块.加载模块使用require方法,该方法读取一个文件并执行,最后返回 ...

  5. Cocos2d 之FlyBird开发---GamePlay类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 这个是游戏的核心部分:(FlyBird游戏重中之重) 创建一个物理世界(世界设置重力加速度) 在物理世界中添加一个动态的刚体(小鸟) 在物 ...

  6. 二、python基础之列表、元组

    一.列表 列表的概念: 列表由一系列按特定顺序排列的元素组成.你可以创建包含字母表中所有字母.数字0-9或所有家庭成员姓名的列表:也可以将任何东西加入列表中,其中的元素之间没有任何关系.鉴于列表通常包 ...

  7. 解决“每次打开office2010的word都会出现配置进度框”问题

       在win7中安装完office2010后.打开 *.doc文件时,总会弹出"配置进度框"问题,解决例如以下:  1)点击"開始"-->"执 ...

  8. Logback配置,error和普通日志分离

    <?xml version="1.0" encoding="utf-8"?> <configuration> <springPro ...

  9. linux随笔-06

    用户身份与文件权限 用户身份与能力 Linux系统的管理员之所以是root,并不是因为它的名字叫root,而是因为该用户的身份号码即UID(User IDentification)的数值为0. 在Li ...

  10. Codeforces 364E 分治

    题意:给你一个01矩阵,问此矩阵有多少个和恰好为k的子矩形. 思路:分治,对于当前矩形,用一条中线把矩形分成两半,分治之后计算跨过中线的矩形个数.更具体的来说(假设划了一条水平中线),我们枚举矩形左右 ...