当我执行以下操作时,它似乎设置了一个常规密钥,而不是外键:
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表中的约束呢?
发布于 2017-03-11 21:34:01
MyISAM存储引擎不支持外键约束。
ENGINE=MYISAM InnoDB存储引擎支持引用完整性约束。(需要使用InnoDB存储引擎定义引用表和引用表。)
ENGINE=INNODBMySQL确实接受MyISAM表的外键约束语法,但是MySQL忽略了外键。语法被接受的最可能的原因是为了使从其他数据库迁移DDL变得更容易。
https://stackoverflow.com/questions/42740873
复制相似问题