我想引用一個外鍵到它的父鍵在MySQL中,我得到一個尷尬的錯誤。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 - 無法創建表(錯誤: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);
我做什麼我錯了 '腳本#SQL-5203_110b8ba。'?
嘗試:: 'ALTER TABLE網站MODIFY外鍵(cms_id)參考cms_technology( ID)' – 2013-02-10 07:39:07