我在创建表"register"
时遇到错误...
共有5个表astro-info
,expectations
,familybackground
,personal_info
,service-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
答案 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
表格字段。