我在插入 MySQL 表 DESP_Features_Weak 中的复合键时遇到问题。
我已经查看了 FK 上唯一的 MySQL 组合,但我的问题有点不同。
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 文档中阅读了一些人似乎已经放弃了他们的索引来解决他们的问题;我做了同样的事情,它似乎没有改变任何东西,尽管我相信仍然有一个名为 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;
/