MySQL:导入时重复键名

骨髓钳

在对数据库进行mysqldump转换后,出现问题,当我尝试重新导入它时,出现“重复键名”错误。

    DROP TABLE IF EXISTS `et_prevision`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `et_prevision` (
  `pk_prevision` int(11) NOT NULL AUTO_INCREMENT,
  `fk_account` int(11) NOT NULL,
  `fk_nature` int(11) NOT NULL,
  `fk_prevision_level` int(11) NOT NULL,
  `fk_analysis_axis1` int(11) DEFAULT NULL,
  `fk_analysis_axis2` int(11) DEFAULT NULL,
  `fk_creator` int(11) DEFAULT NULL,
  `fk_modifier` int(11) DEFAULT NULL,
  `fk_reconciliation` int(11) DEFAULT NULL,
  `fk_sicav` int(11) DEFAULT NULL,
  `fk_rate` int(11) DEFAULT NULL,
  `fk_prevision` int(11) DEFAULT NULL,
  `fk_funding` int(11) DEFAULT NULL,
  `operation_date` date NOT NULL,
  `value_date` date NOT NULL,
  `creation_date` date NOT NULL,
  `modification_date` date NOT NULL,
  `status` int(11) DEFAULT NULL,
  `amount` decimal(14,5) NOT NULL,
  `libelle` varchar(255) DEFAULT NULL,
  `piece_number` varchar(15) DEFAULT NULL,
  `commentaire` varchar(255) DEFAULT NULL,
  `reconciliation_libelle` varchar(255) DEFAULT NULL,
  `monitored` int(11) DEFAULT NULL,
  `operation_count` int(11) NOT NULL,
  `is_subscription` int(11) DEFAULT NULL,
  `cycling` int(11) DEFAULT NULL,
  `cycle_count` int(11) DEFAULT NULL,
  `remittance_reference` varchar(35) DEFAULT NULL,
  `is_principal` int(11) DEFAULT NULL,
  `sicav_parts_count` decimal(14,5) DEFAULT NULL,
  `sicav_rate` decimal(14,5) DEFAULT NULL,
  `investment_margin` decimal(14,5) DEFAULT NULL,
  `investment_effective_rate` decimal(14,5) DEFAULT NULL,
  `investment_day_count` int(11) DEFAULT NULL,
  `investment_count_type` int(11) DEFAULT NULL,
  `attachment_file_name` varchar(255) DEFAULT NULL,
  `investment_type` int(11) DEFAULT NULL,
  `print_date` date DEFAULT NULL,
  `prevision_batch` int(11) NOT NULL,
  `fk_interface` int(6) DEFAULT NULL,
  PRIMARY KEY (`pk_prevision`),
  KEY `fk_prev_account` (`fk_account`),
  KEY `fk_prev_nature` (`fk_nature`),
  KEY `fk_prev_prevision_level` (`fk_prevision_level`),
  KEY `fk_prev_analysis_axis1` (`fk_analysis_axis1`),
  KEY `fk_prev_fk_analysis_axis2` (`fk_analysis_axis2`),
  KEY `fk_prev_creator` (`FK_CREATOR`),
  KEY `fk_prev_modifier` (`FK_MODIFIER`),
  KEY `fk_prev_reconciliation` (`fk_reconciliation`),
  KEY `fk_prev_sicav` (`fk_sicav`),
  KEY `fk_prev_rate` (`fk_rate`),
  KEY `fk_prev_prev` (`fk_prevision`),
  KEY `fk_prev_funding` (`fk_funding`),
  KEY `fk_interface_to_interface` (`FK_INTERFACE`),
  CONSTRAINT `fk_interface_to_interface` FOREIGN KEY (`FK_INTERFACE`) REFERENCES `et_p_interface` (`pk_interface`) ON DELETE SET NULL,
  CONSTRAINT `fk_prev_account` FOREIGN KEY (`fk_account`) REFERENCES `t_account` (`PK_ID`),
  CONSTRAINT `fk_prev_analysis_axis1` FOREIGN KEY (`fk_analysis_axis1`) REFERENCES `et_p_axe_analyse_2` (`pk_axe_analyse_2`) ON DELETE SET NULL,
  CONSTRAINT `fk_prev_creator` FOREIGN KEY (`fk_creator`) REFERENCES `t_user` (`PK_ID`),
  CONSTRAINT `fk_prev_fk_analysis_axis2` FOREIGN KEY (`fk_analysis_axis2`) REFERENCES `et_p_axe_analyse_3` (`pk_axe_analyse_3`) ON DELETE SET NULL,
  CONSTRAINT `fk_prev_funding` FOREIGN KEY (`fk_funding`) REFERENCES `et_funding` (`pk_funding`),
  CONSTRAINT `fk_prev_modifier` FOREIGN KEY (`fk_modifier`) REFERENCES `t_user` (`PK_ID`),
  CONSTRAINT `fk_prev_nature` FOREIGN KEY (`fk_nature`) REFERENCES `et_p_nature` (`pk_nature`),
  CONSTRAINT `fk_prev_prev` FOREIGN KEY (`fk_prevision`) REFERENCES `et_prevision` (`pk_prevision`),
  CONSTRAINT `fk_prev_prevision_level` FOREIGN KEY (`fk_prevision_level`) REFERENCES `et_p_prevision_level` (`pk_prevision_level`),
  CONSTRAINT `fk_prev_rate` FOREIGN KEY (`fk_rate`) REFERENCES `et_p_rate` (`pk_rate`),
  CONSTRAINT `fk_prev_reconciliation` FOREIGN KEY (`fk_reconciliation`) REFERENCES `et_reconciliation` (`pk_reconciliation`) ON DELETE SET NULL,
  CONSTRAINT `fk_prev_sicav` FOREIGN KEY (`fk_sicav`) REFERENCES `et_p_sicav` (`pk_sicav`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

该错误发生在“ fk_prev_creator”键上。我确定我在数据库的任何地方都没有同名的键,并且尝试将其重命名为“ fk_prev_creator1”,这给了我同样的错误。我尝试删除密钥声明,并且在“ fk_prev_modifier”上引发了另一个错误。如果删除两个密钥声明,则一切正常,但是,由于此转储应用于安装目的,我想知道为什么这些精确密钥不能按预期工作。

编辑:就您的信息而言,转储和导入都是在mysql 5.1.33下的服务器上进行的。

Edit2:我尝试导入5.6.X服务器,它的工作原理很吸引人。因此,它似乎与MySQL版本有关,但是我没有找到有关此问题的任何错误报告。

谢谢你。

骨髓钳

因此,我终于找到了为什么导入无法正常工作的原因。如果您仔细查看KEy声明:

  KEY `fk_prev_creator` (`FK_CREATOR`),
  KEY `fk_prev_modifier` (`FK_MODIFIER`),

它们与CONSTRAINTS声明略有不同:

CONSTRAINT `fk_prev_creator` FOREIGN KEY (`fk_creator`) REFERENCES `t_user` (`PK_ID`),
CONSTRAINT `fk_prev_modifier` FOREIGN KEY (`fk_modifier`) REFERENCES `t_user` (`PK_ID`),

区别在于,在KEY声明中,字段名称用大写字母表示,而不在CONSTRAINT声明中。在5.1.X中,这很重要,而在5.6.X中则没有关系,因此在这种情况下,MySQL认为它就像我试图声明另一个规则一样,并且不喜欢它。

tl; dr:5.1.X在此特定情况下区分大小写。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章