在 mysql Ver 14.14 Distrib 5.1.66 上,对于 unknown-linux-gnu (x86_64),MySQL 外键约束没有得到尊重/尊重的问题。
数据库/表结构从未被修改过,也就是:这是原始且唯一的表结构。
这是标准 mysqldump 的结果。
-- Table structure for table `catalog_category_entity_int`
DROP TABLE IF EXISTS `catalog_category_entity_int`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `catalog_category_entity_int` (
`value_id` int(11) NOT NULL AUTO_INCREMENT,
`entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`store_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`entity_id` int(10) unsigned NOT NULL DEFAULT '0',
`value` int(11) DEFAULT NULL,
PRIMARY KEY (`value_id`),
UNIQUE KEY `IDX_BASE` (`entity_type_id`,`entity_id`,`attribute_id`,`store_id`),
KEY `FK_ATTRIBUTE_INT_ENTITY` (`entity_id`),
KEY `FK_CATALOG_CATEGORY_EMTITY_INT_ATTRIBUTE` (`attribute_id`),
KEY `FK_CATALOG_CATEGORY_EMTITY_INT_STORE` (`store_id`),
CONSTRAINT `FK_CATALOG_CATEGORY_EMTITY_INT_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_CATALOG_CATEGORY_EMTITY_INT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_CATALOG_CATEGORY_EMTITY_INT_STORE` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE)
ENGINE=InnoDB AUTO_INCREMENT=1483 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
看:
唯一键IDX_BASE
( entity_type_id
, entity_id
, attribute_id
, store_id
)
Error:
Query:
INSERT INTO `catalog_category_entity_int` VALUES (1,3,32,0,2,1),(2,3,32,1,2,1),(6,3,32,0,4,1),[...];
MySQL said: Documentation
#1062 - Duplicate entry '3-144-40-0' for key 'IDX_BASE'
我从来没有见过这种情况发生,知道这怎么可能吗?