解决MySQL创建外键时ERROR 1005, errorno:150的错误
2014-10-17 14:04
537 查看
由于项目中的有数据结构的变更,今天在执行DDL的时候创建外键死活不成功,老是报ERROR 1005 (HY000): Can't create table '.\env_abc\#sql-958_7.sql' (errno: 150),根本就没有这个sql嘛。
网上搜索结果:
在MySQL Manual里找到“errno 150”,要看错误的详细提示,可以使用命令
SHOW ENGINE INNODB STATUS; //针对用INNODB存储方式的数据库,
在信息中有一组【LATEST FOREIGN KEY ERROR】会有最近错误的详细描述和解决办法。
如: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.(不能在“被reference的表”里找到包含“被reference字段”的索引,或者是两个关联字段类型不匹配)
但是发现自己的sql两边的结构都是一样的,经过死命折腾,终于找到原因了:
由于现在的库要区分大小写,数据库设置了字符集utf8和校验字符集utf8_bin,但是执行的DDL是从PDM中拷贝过来的,没有带字符集设置(ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin),所以mysql识别出两边的字段类型不匹配,后来把执行的DDL加上ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin,重新执行下就可以了。
网上搜索结果:
在MySQL Manual里找到“errno 150”,要看错误的详细提示,可以使用命令
SHOW ENGINE INNODB STATUS; //针对用INNODB存储方式的数据库,
在信息中有一组【LATEST FOREIGN KEY ERROR】会有最近错误的详细描述和解决办法。
如: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.(不能在“被reference的表”里找到包含“被reference字段”的索引,或者是两个关联字段类型不匹配)
但是发现自己的sql两边的结构都是一样的,经过死命折腾,终于找到原因了:
由于现在的库要区分大小写,数据库设置了字符集utf8和校验字符集utf8_bin,但是执行的DDL是从PDM中拷贝过来的,没有带字符集设置(ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin),所以mysql识别出两边的字段类型不匹配,后来把执行的DDL加上ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin,重新执行下就可以了。
相关文章推荐
- MySQL创建外键时错误:MySQL Error Number 1005 Can’t create table ‘XX.frm’ (errno: 150)
- MySQL创建外键出现 ERROR 1005: Can't create table (errno: 150)解决办法
- MySQL中创建外键参照时的句法错误(errno:150)解决办法
- 解析在MySQL里创建外键时ERROR 1005的解决办法
- 解析在MySQL里创建外键时ERROR 1005的解决办法
- [MySQL]表创建外键失败:ERROR 1005 (HY000): Can't create table (errno: 150)
- MySQL 外键创建表失败 ERROR 1005 (HY000): Can't Create Table....(errno: 150)
- 【MySQL】ERROR 1005: Can't create table (errno: 150)的错误解决办法
- Mysql创建表或外键约束时出现1005错误代码的解决方法
- mysql 建立外键错误(mysql error number 1005 errno: 150)
- 编译Mysql时configure: error: No curses/termcap library found 的错误解决方法
- 编译Mysql时configure: error: No curses/termcap library found 的错误解决方法
- mysql error Number 1005之errno150解决
- 编译Mysql时configure: error: No curses/termcap library found 的错误解决方法
- mysql创建外键错误的解决方法
- 安装mysql,在./configure时出现错误:error: No curses/termcap library found的解决办法
- 编译Mysql时configure: error: No curses/termcap library found 的错误解决方法
- 编译Mysql时configure: error: No curses/termcap library found 的错误解决方法
- 更新:编译Mysql时configure: error: No curses/termcap library found 的错误解决方法
- MySQL创建外键失败,错误信息1005