MYSQL中ERROR 1005 (HY000): Can't create table 错误

今天修复一个MYSQL数据库时遇到的一个小问题:

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 '2000-01-01 00:00:00',
  `employee_tel` varchar(64) default NULL,
  `employee_sex` varchar(16) default NULL,
  `sell_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 1005 (HY000): Can't create table './supererpthree/#sql-2491_cceb2.frm' (errno: 150)

主要问题是:

 FOREIGN KEY (`fk_employee_id`) REFERENCES `erp_employee` (`id`) 中`erp_receiver_shop`表的 `fk_employee_id`   是int和`erp_employee`表中的id设置的关联字段类型不匹配,`erp_receiver_shop`表中`fk_employee_id` 改正成:`fk_employee_id`  int(10) unsigned  NOT NULL ,就不会报错了,创修改表地时候常常一步小小就忘记了这个.

以前遇到一次,今天又犯了一次 下不为例。


你可能感兴趣的:(mysql)