我试图在 mysql 中将外键引用到其父键,但出现了一个尴尬的错误。
我尝试了以下方法。
ALTER TABLE `website`
ADD CONSTRAINT `website_cms_fk1` FOREIGN KEY (`cms_id`) REFERENCES `cms_technology` (`ID`);
还
ALTER TABLE website ADD FOREIGN KEY (cms_id) REFERENCES cms_technology (ID)
我收到以下错误。
*#1005 - 无法创建表 'script.#sql-5203_110b8ba' (errno: 150)*
以下是我的表格
CREATE TABLE IF NOT EXISTS `cms_technology` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`cms_name` varchar(250) NOT NULL DEFAULT '',
`cms_description` varchar(250) NOT NULL DEFAULT '',
PRIMARY KEY (`ID`)
);
INSERT INTO `cms_technology` (`ID`, `cms_name`, `cms_description`) VALUES
(1, 'Wordpress', 'WordPress › Blog Tool, Publishing Platform, and CMS');
CREATE TABLE IF NOT EXISTS `website` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`website_url` varchar(60) NOT NULL DEFAULT '',
`website_ip` varchar(20) NOT NULL DEFAULT '',
`website_title` varchar(250) NOT NULL DEFAULT '',
`website_status` varchar(10) NOT NULL DEFAULT '',
`website_scanned` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`website_response` int(3) NOT NULL DEFAULT '0',
`cms_id` int(5) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`)
);
INSERT INTO `website` (`ID`, `website_url`, `website_ip`, `website_title`, `website_status`, `website_scanned`, `website_response`, `website_cms`) VALUES
(1, 'http://www.wpbeginner.com/', '', '', '', '0000-00-00 00:00:00', 0, 0);
我做错了什么?