MySQL INSERT失败,弱实体的复合键:关键'PRIMARY'的“重复录入”

时间:2012-05-24 12:45:56

标签: mysql composite-key mysql-error-1062

我在MySQL表DESP_Features_Weak中使用复合键INSERTING时出现问题。

我已经看过了 MySQL composite unique on FK's,但我的问题有点不同。

My ERD

INSERT INTO DESP_Features_Weak (details, Features_f_id, fk_desp_id, fk_dfws_id) VALUES (NULL, 2, 1, 5);

产量,

Error Code: 1062. Duplicate entry '1-2' for key 'PRIMARY'

但奇怪的是,使用1,2键(甚至是2,1键)搜索记录时不会返回任何记录,因此没有重复的条目。

我在MySQL documentation读过,有些人似乎放弃了他们的索引以解决他们的问题;我做了同样的事情似乎并没有改变任何东西,虽然我相信还有一个名为PRIMARY的索引我无法放弃。

这只是我在MySQL Workbench中汇总的个人数据库,它不在生产中或任何其他内容。

相关表的转储如下所示:

CREATE TABLE `DESP_Features_Weak` (
  `DESP_Features_Weakcol` varchar(45) DEFAULT NULL,
  `Details` mediumtext,
  `fk_desp_id` int(11) NOT NULL,
  `Features_f_id` int(11) NOT NULL,
  `CostType_ct_id` int(11) NOT NULL,
  `cost_amount` decimal(18,2) DEFAULT NULL,
  `askedAboutFeatureFees` tinyint(1) DEFAULT NULL,
  `fk_dfws_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`fk_desp_id`,`Features_f_id`),
  KEY `fk_DESP_Features_Weak_Features1` (`Features_f_id`),
  KEY `fk_DESP_Features_Weak_DESP_Feature_Weak_State1` (`fk_dfws_id`),
  CONSTRAINT `fk_DESP_Features_Weak_DigitalEditionsSolutionProvider1` FOREIGN KEY (`fk_desp_id`) REFERENCES `DigitalEditionsSolutionProvider` (`desp_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_DESP_Features_Weak_DESP_Feature_Weak_State1` FOREIGN KEY (`fk_dfws_id`) REFERENCES `DESP_Feature_Weak_State` (`dfws_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_DESP_Features_Weak_Features1` FOREIGN KEY (`Features_f_id`) REFERENCES `Features` (`f_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/

0 个答案:

没有答案