MySQL error 1005 (hy000): Can't create table Error

Source: Internet
Author: User

Today, we fixed a small problem encountered in a MySQL database:

Create Table 'erp _ employee '(
'Id' int (10) unsigned not null auto_increment,
'Employee _ name' varchar (32) default null,
'User _ id' int (11) default null,
'Type' varchar (32) default null,
'Gmt _ create' timestamp not null default current_timestamp,
'Gmt _ modified' timestamp not null default '2017-01-01 00:00:00 ',
'Employee _ Tel 'varchar (64) default null,
'Employee _ sex' varchar (16) default null,
'Your _ money' double default '0 ',
'Per _ price' double default '0 ',
'Order _ num' int (10) unsigned default '0 ',
'Response _ time' int (10) unsigned default '0 ',
'Order _ no_pay' int (10) unsigned default '0 ',
'Pay _ num' int (10) unsigned not null default '0 ',
'Order _ no_pay_money 'Double not null default '0 ',
'Receive _ num' int (10) unsigned not null default '0 ',
'Order _ change_rate 'double not null default '0 ',
'Is _ deleted' varchar (2) not null default 'n ',
'Pay _ per_num 'int (11) default null,
Primary Key ('id ')

) Engine = InnoDB default charset = utf8;

Create Table 'erp _ receiver_shop '(
'Id' int (11) not null auto_increment,
'Fk _ employee_id 'int (10) Not null,
'Nick _ name' varchar (64) default null,
'Gmt _ create' timestamp not null default current_timestamp,
'User _ id' int (11) default null,
Primary Key ('id '),
Key 'fk _ employee_id '('fk _ employee_id '),
Constraint 'fk _ employee_id 'foreign key ('fk _ employee_id') References 'erp _ employee '('id') on Delete Cascade
) Engine = InnoDB default charset = utf8;

Error:

Error 1005 (hy000): Can't create table './supererpthree/# sql-2491_cceb2.frm' (errno: 150)

The main problems are:

Foreign key ('fk _ employee_id ') References 'erp _ employee' ('id ') the 'fk _ employee_id 'in the 'erp _ receiver_shop' table does not match the associated field type set by the ID in the 'erp _ employee' table, in the 'erp _ receiver_shop 'table, change 'fk _ employee_id' to 'fk _ employee_id 'int (10) unsigned not null, so no error is reported, when creating and modifying a table, you often forget this step.

Once in the past, today I made another mistake.

Related Article

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.