无法添加外键mysql

时间:2017-02-15 21:29:05

标签: mysql foreign-keys foreign-key-relationship

我正在尝试向MySQL添加一个新表,但我得到无法添加外键约束错误。

我想要执行的SQL是:

CREATE TABLE `local_news` (
  `local_news_id` int(11) NOT NULL AUTO_INCREMENT,
  `org_id` int(11) NOT NULL,
  `org_contact_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL COMMENT 'title',
  `message` text DEFAULT NULL,
  `published` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0-draft, 1-published',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`local_news_id`),
  KEY `FK_Reference_56` (`org_id`),
  KEY `FK_Reference_57` (`org_contact_id`),
  CONSTRAINT `FK_Reference_56` FOREIGN KEY (`org_id`) REFERENCES `organization` (`org_id`),
  CONSTRAINT `FK_Reference_57` FOREIGN KEY (`org_contact_id`) REFERENCES `org_contacts` (`contact_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='All local site content in the news tab';

我的组织'表格包含' org_id' as int(11)并设置为主键。

我的' org_contacts'表格有' contact_id' as int(11)并设置为主键。

我发现的完整错误(使用show engine innodb status时)是:

  

------------------------最新外国关键错误   ------------------------ 2017-02-15 22:28:27 0x2b64表giveaday / local_news的外键约束出错:

FOREIGN KEY (`org_id`) REFERENCES `organization` (`org_id`),
 CONSTRAINT `FK_Reference_57` FOREIGN KEY (`org_contact_id`) REFERENCES `org_contacts` (`contact_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='All local site content in the news tab':
Cannot resolve table name close to:
(`org_id`),
 CONSTRAINT `FK_Reference_57` FOREIGN KEY (`org_contact_id`) REFERENCES `org_contacts` (`contact_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='All local site content in the news tab'
     

然而,表"组织"确实存在并被称为"组织",没有拼写错误。

0 个答案:

没有答案