无法创建表errno150

时间:2014-03-17 07:42:56

标签: mysql xampp

我在创建表"register"时遇到错误... 共有5个表astro-infoexpectationsfamilybackgroundpersonal_infoservice-business

我检查了所有外键的数据类型和大小。他们是一样的。即bigint(100)表示其他表中的所有primaty键。但我仍然得到这个错误...

请帮忙......

这是我的表结构......

create table register(
    register_id bigint(100) primary key,
    mv_id bigint(100),
    astro_id bigint(100),
    foreign key(astro_id) 
            references `astro-info`(astro_id),
    expectation_id bigint(100),
    foreign key(expectation_id) 
            references `expectations`(expectation_id),
    familybackground_id bigint(100),
    foreign key(familybackground_id) 
            references `familybackground`(familybackground_id),
    personal_info_id bigint(100),
    foreign key(personal_info_id) 
            references `personal_info`(personal_info_id),
    service_id bigint(100),
    foreign key(service_id) 
            references `service-business`(service_id));

astro-info

的表结构
CREATE TABLE IF NOT EXISTS `astro-info` (
  ` astro_id` bigint(100) NOT NULL AUTO_INCREMENT,
  -- other irrelevant fields removed from here
  PRIMARY KEY (` astro_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

expectations

的表结构
CREATE TABLE IF NOT EXISTS `expectations` (
  `expectation_id` bigint(100) NOT NULL AUTO_INCREMENT,
  -- other irrelevant fields removed from here
  PRIMARY KEY (`expectation_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

familybackground

的表结构
CREATE TABLE IF NOT EXISTS `familybackground` (
  `familybackground_id` bigint(100) NOT NULL AUTO_INCREMENT,
  -- other irrelevant fields removed from here
  PRIMARY KEY (`familybackground_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9

personal_info

的表结构
CREATE TABLE IF NOT EXISTS `personal_info` (
  `personal_info_id` bigint(100) NOT NULL AUTO_INCREMENT,
  -- other irrelevant fields removed from here
  PRIMARY KEY (`personal_info_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10

service-business

的表结构
CREATE TABLE IF NOT EXISTS `service-business` (
  `service_id` bigint(100) NOT NULL AUTO_INCREMENT,
  -- other irrelevant fields removed from here
  PRIMARY KEY (`service_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 

1 个答案:

答案 0 :(得分:0)

您的表astro-info中存在错误。

CREATE TABLE IF NOT EXISTS `astro-info` (
  ` astro_id` bigint(100) NOT NULL AUTO_INCREMENT,
  -- other irrelevant fields removed from here
  PRIMARY KEY (` astro_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

错误发生在两个地方:

  ` astro_id` bigint(100) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (` astro_id`)

它有一个带列名的前导空格。在regster表中的列上定义外键时未使用相同的内容。

create table register(
    register_id bigint(100) primary key,
    mv_id bigint(100),
    astro_id bigint(100),
    foreign key(astro_id) 
            references `astro-info`(astro_id),
    expectation_id bigint(100),
    foreign key(expectation_id) 
            references `expectations`(expectation_id),
    familybackground_id bigint(100),
    foreign key(familybackground_id) 
            references `familybackground`(familybackground_id),
    personal_info_id bigint(100),
    foreign key(personal_info_id) 
            references `personal_info`(personal_info_id),
    service_id bigint(100),
    foreign key(service_id) 
            references `service-business`(service_id));

register表中的这个定义

    astro_id bigint(100),
    foreign key(astro_id) 
            references `astro-info`(astro_id),

astro-info

中的以下定义不匹配
  ` astro_id` bigint(100) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (` astro_id`)

<强>解决方案
选项1 :在` astro_id`表格中将`astro_id`重新定义为astro-info

选项2 :Redifine astro_id有一个前导空格。与` astro_id`中一样。

我的建议是使用选项1 ,修改astro-info表格字段。