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

Source: Internet
Author: User

CREATE TABLE ' user ' (
' ID ' bigint (+) not NULL auto_increment,
' Name ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci not NULL,
' ERP ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci not NULL DEFAULT ' ',
' Email ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Department ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Position ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Role ' int (1) is not NULL,
' Lastproductid ' bigint (+) null DEFAULT null,
' Userip ' varchar (+) 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 (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Ho2name ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Ho3name ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Ho4name ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Ho5name ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Modifytime ' datetime null DEFAULT NULL,
' DefaultType ' int (one) 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 (+) not NULL auto_increment,
' ERP ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci not NULL,
' Opertype ' int (one) not NULL DEFAULT 0 COMMENT ' 1---login ',
' Opertime ' datetime not NULL,
' Remark ' varchar ($) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Browerip ' varchar (+) CHARACTER SET UTF8 COLLATE utf8_general_ci null DEFAULT NULL,
' Modifytime ' datetime not NULL,
PRIMARY KEY (' id '),
FOREIGN KEY (' ERP ') REFERENCES ' user ' (' ERP ') on the DELETE CASCADE on UPDATE RESTRICT
)
Engine=innodb
DEFAULT CHARACTER Set=utf8 Collate=utf8_general_ci
auto_increment=2247
;

The error message is as follows:

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 the 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 does 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 is 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.


There are several reasons for the error:
1. Inconsistent field types
2. The referenced field and the referenced field "NULL" attribute are inconsistent
3. No index was created for the referenced table


The above error is due to the fact that no index is created for the referenced field.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.