ERROR 1005 (HY000): Can't create table'matrix.system_log' (errno: 150)

CREATE TABLE `user` (
`id` bigint(32) NOT NULL AUTO_INCREMENT ,
`name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`erp` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT ‘‘ ,
`email` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`department` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`position` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`role` int(1) NOT NULL ,
`lastProductID` bigint(32) NULL DEFAULT NULL ,
`userIP` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`debugRunStatus` int(1) NULL DEFAULT NULL ,
`createTime` datetime NULL DEFAULT NULL ,
`remark` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`ho1Name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`ho2Name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`ho3Name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`ho4Name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`ho5Name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`modifyTime` datetime NULL DEFAULT NULL ,
`defaultType` int(11) NULL DEFAULT NULL ,
PRIMARY KEY (`id`, `erp`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=486
;

CREATE TABLE `system_log` (
`id`  bigint(32) NOT NULL AUTO_INCREMENT ,
`erp`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`operType`  int(11) NOT NULL DEFAULT 0 COMMENT ‘1 ---登录‘ ,
`operTime`  datetime NOT NULL ,
`remark`  varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`browerIP`  varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`modifyTime`  datetime NOT NULL ,
PRIMARY KEY (`id`),
FOREIGN KEY (`erp`) REFERENCES `user` (`erp`) ON DELETE CASCADE ON UPDATE RESTRICT
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=2247
;

报错信息如下:

ERROR 1005 (HY000): Can‘t create table ‘matrix.system_log‘ (errno: 150)

mysql> show engine innodb status\G

140303 13:58:42 Error in foreign key constraint of table matrix/system_log:
FOREIGN KEY (`erp`) REFERENCES `user` (`erp`) ON DELETE CASCADE ON UPDATE RESTRICT
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=2247:
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.5/en/innodb-foreign-key-constraints.html
for correct foreign key definition.

报错原因有如下几种原因:
1.字段类型不一致
2.引用的字段和被引用的字段“NULL”属性不一致
3.为引用的表没有创建索引

上述报错是因为没有为引用的字段创建索引。

ERROR 1005 (HY000): Can't create table'matrix.system_log' (errno: 150)

时间: 2024-10-14 11:40:28

ERROR 1005 (HY000): Can't create table'matrix.system_log' (errno: 150)的相关文章

Mysql错误问题:ERROR 1005 (HY000): Can't create table 'crm_1.tbl_client' (errno: 150)

MySQL外键创建条件: 1.两个表必须是InnoDB数据引擎2.外键表的外键字段必须是主键3.字段类型必须一致 创建表时创建外键: create table tbl_client(userName varchar(255) not null, address varchar(255), createDate timestamp not null default now(), createUserName varchar(255), foreign key(createUserName) ref

ERROR 1005 (HY000): Can't create table 'sakila.book2' (errno: 150)

mysql> create table user2(     -> id int,     -> name varchar(10),     -> primary key(id))     -> engine=innodb; Query OK, 0 rows affected (0.02 sec) mysql>  create table book2(     ->  id int,     ->  bookname varchar(10),     -&g

错误代码: 1005 Can't create table 'hibernate.bill' (errno: 150)

主要问题以及解决办法是: 1,MySQL支持外键约束,并提供与其它DB相同的功能,但表(外键表和外键主表)类型必须为 InnoDB,外键表和外键主表的类型都要是innoDB 建表约束语句: user表: 1 2 3 4 5 6 CREATE TABLE `usert` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `password` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,   `userNa

mysql为表添加外键完成性约束 报错Can't create table 'sfkbbs.#sql-513_25' (errno: 150)

代码 alter table sfk_son_module add constraint foreign key(father_module_id) references sfk_father_module(id) on delete restrict on update restrict; (constraint 后面可以加上约束名字) 错误原因是之前两张表的id的类型不一样,一个时int,一个时bigint 解决办法时修改表, alter table sfk_father_module mo

ERROR 1 (HY000): Can‘t create/write to file ‘/data

使用非DBA用户进行load data 操作,发现报错. MariaDB [temp_archive]> select * from t1 into outfile '/data/test.sql'; ERROR 1 (HY000): Can't create/write to file '/data/test.sql' (Errcode: 13 "Permission denied") 提示报错. 报错原因权限不足. 分析: 权限有系统权限和数据库权限. /data 目录权限

ERROR 1 (HY000): Can't create/write to file '/tmp/#sql_830_0.MYI' (Errcode: 13)

mysql操作时,出现报错. 执行describe 命令时, 临时文件目录没有创建或者无写入权限:于是: cd /var/lib/mysql/ #进入mysql数据目录 mkdir tmp #创建需要的临时目录 chown mysql.mysql /var/lib/mysql/tmp #给临时目录分配mysql权限用户及群组 ERROR 1 (HY000): Can't create/write to file '/tmp/#sql_830_0.MYI' (Errcode: 13)

ERROR 1 (HY000): Can't create/write to file '/tmp/#sql_909_0.MYI' (Errcode: 13)

mysql> desc tablename; ERROR 1 (HY000): Can't create/write to file '/tmp/#sql_909_0.MYI' (Errcode: 13) 两种解决办法:方法一:1.chmod 777 /tmp[[email protected] /]# chmod 777 /tmpchmod: 更改"/tmp" 的权限: 只读文件系统 --遇到这种情况,tmp权限无法更改. 2./etc/init.d/mysqld start

ERROR 1 (HY000): Can't create/write to file '/tmp/#sql_4188_1.MYI' (Errcode: 28)

mysql Errcode 28 磁盘还可以但是inode表没有了 dd if=/dev/zero of=tmpforinde count=1024 bs=1024KB mke2fs -N 5000000 -b 1024 -I 128 tmpforinde #格式化成ext2分区(因为ext3有日志系统,会消耗空间),制定inode大小为 mount -o loop tmpforinde /var/tmp [email protected]:/var# df -h Filesystem Size

mysql ERROR 1005

mysqldump 导出备份后用mysq还原报错 ERROR 1005 (HY000) at line 1001: Can't create table '' (errno: 121) 删除mysql的ibdata1.ib_logfile0.ib_logfile1 再试试,记得备份哦.