【发布时间】:2017-08-02 03:01:00
【问题描述】:
当我执行以下操作时,它看起来像是设置了一个常规 KEY,而不是外键:
ALTER TABLE `dev1_IMGStoreTmpComponents`
ADD CONSTRAINT `con_fk_templates`
FOREIGN KEY `fk_templates`(`templateId`)
REFERENCES `dev1_IMGStoreTemplates`(`templateId`)
SQL 运行成功。
然后我运行这个:
SHOW CREATE TABLE `dev1_IMGStoreTmpComponents`;
CREATE TABLE `dev1_IMGStoreTmpComponents` (
`componentId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8mb4_unicode_520_ci NOT NULL,
`description` varchar(250) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`templateId` int(10) unsigned NOT NULL,
`type` char(3) COLLATE utf8mb4_unicode_520_ci NOT NULL,
`layer` tinyint(3) unsigned DEFAULT NULL,
`posx` mediumint(8) unsigned NOT NULL,
`posy` mediumint(8) unsigned NOT NULL,
`width` mediumint(8) unsigned NOT NULL,
`height` mediumint(8) unsigned NOT NULL,
`settings` text COLLATE utf8mb4_unicode_520_ci,
PRIMARY KEY (`componentId`),
UNIQUE KEY `componentId` (`componentId`,`templateId`),
KEY `con_fk_templates` (`templateId`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci COMMENT='Template Components'
为什么我在 Create 表中看不到 CONSTRAINT?
【问题讨论】:
标签: mysql