MySQL外键约束没有得到尊重/尊重

时间:2013-10-25 18:13:07

标签: php mysql sql magento mysqldump

对于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_BASEentity_type_identity_idattribute_idstore_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' 

我从来没有见过这种情况,关于如何做到这一点的任何想法?

1 个答案:

答案 0 :(得分:0)

我能够复制此功能的唯一方法是使用以下命令关闭数据导入的外部/唯一检查:

SET FOREIGN_KEY_CHECKS = 0;
SET UNIQUE_CHECKS = 0;

这必须在某个时候设置为导入。不知道为什么有人会这样做,但是,这肯定是发生了什么。

相关问题