Mysql 我不能';t在表中创建外键。我该怎么办?

Mysql 我不能';t在表中创建外键。我该怎么办?,mysql,sql,phpmyadmin,foreign-keys,Mysql,Sql,Phpmyadmin,Foreign Keys,我的表格名为add_disease和specificity_of_gender。我想在add\u disease表中将specificity\u of_gender表的主键设置为外键。我的代码如下: -- -- Table structure for table `add_disease` -- CREATE TABLE IF NOT EXISTS `add_disease` ( `Disease_Id` int(100) NOT NULL AUTO_INCREMENT, `Diseas

我的表格名为
add_disease
specificity_of_gender
。我想在
add\u disease
表中将
specificity\u of_gender
表的主键设置为外键。我的代码如下:

--
-- Table structure for table `add_disease`
--
CREATE TABLE IF NOT EXISTS `add_disease` (
  `Disease_Id` int(100) NOT NULL AUTO_INCREMENT,
  `Disease_Name` varchar(100) NOT NULL,
  `Gender_Id` int(100) NOT NULL,
  `Age_Id` int(100) NOT NULL,
  `Notion_Id` int(100) NOT NULL,
  `Type_Id` int(100) NOT NULL,
  `Stage_Id` int(100) NOT NULL,
  `Scope_Id` int(100) NOT NULL,
  `Symptoms` text NOT NULL,
  `Description` text NOT NULL,
  `Image` int(100) NOT NULL,
  PRIMARY KEY (`Disease_Id`),
KEY ` Gender_Id ` (`Gender_Id `),
KEY ` Age_Id ` (`Age_Id `),
KEY ` Notion_Id ` (`Notion_Id `),
KEY ` Type_Id ` (`Type_Id `),
KEY ` Stage_Id ` (`Stage_Id `),
KEY ` Scope_Id ` (`Scope_Id `)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `add_disease`
--**

MySQL说

Error

SQL query:
--
-- Database: `online_medical_service`
--
-- --------------------------------------------------------
--
-- Table structure for table `add_disease`
--
CREATE TABLE IF NOT EXISTS `add_disease` (
`Disease_Id` int( 100 ) NOT NULL AUTO_INCREMENT ,
`Disease_Name` varchar( 100 ) NOT NULL ,
`Gender_Id` int( 100 ) NOT NULL ,
`Age_Id` int( 100 ) NOT NULL ,
`Notion_Id` int( 100 ) NOT NULL ,
`Type_Id` int( 100 ) NOT NULL ,
`Stage_Id` int( 100 ) NOT NULL ,
`Scope_Id` int( 100 ) NOT NULL ,
`Symptoms` text NOT NULL ,
`Description` text NOT NULL ,
`Image` int( 100 ) NOT NULL ,
PRIMARY KEY ( `Disease_Id` ) ,
KEY ` Gender_Id ` ( `Gender_Id ` ) ,
KEY ` Age_Id ` ( `Age_Id ` ) ,
KEY ` Notion_Id ` ( `Notion_Id ` ) ,
KEY ` Type_Id ` ( `Type_Id ` ) ,
KEY ` Stage_Id ` ( `Stage_Id ` ) ,
KEY ` Scope_Id ` ( `Scope_Id ` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT =1;
MySQL说:

#1072 - Key column 'Gender_Id ' doesn't exist in table 

谁能告诉我该怎么办??请帮我做这个…:(

问题在于定义索引时,
列名
索引名
上有额外的空格

PRIMARY KEY (`Disease_Id`),
KEY `bGender_Idb` (`Gender_Id `),
KEY ` Age_Id ` (`Age_Id `),
KEY ` Notion_Id ` (`Notion_Id `),
KEY ` Type_Id ` (`Type_Id `),
KEY ` Stage_Id ` (`Stage_Id `),
KEY ` Scope_Id ` (`Scope_Id `)
所以基本上

`Gender_Id ` is not equal to `Gender_Id`
          ^ see extra spaces from here
你对你所有的专栏都这样做了:
Gender\u Id
Age\u Id
,等等

您应该删除多余的尾随空格,它就会起作用。

下面是固定的
DDL


以后,请将您的代码放在代码示例块中(我已经提交了一份编辑文件),这样可以大大提高您问题的可读性,以便其他用户能够更好地帮助您解决问题。非常感谢您……我将删除多余的空格,如果遇到任何问题,我会让您知道……)
`Gender_Id ` is not equal to `Gender_Id`
          ^ see extra spaces from here