当没有主键时,密钥主要的mysql重复条目

时间:2015-01-15 16:16:36

标签: mysql innodb

我有一个名为document的表。

引擎innodb

所以我需要插入一些以前从该表中删除的记录。

我删除了主键和auto_increment

执行show create table document检查是否已删除

然后,当我运行insert语句时,我收到错误:

[Err] 1062 - Duplicate entry '492' for key 'PRIMARY'


show create table document

CREATE TABLE `document` (
  `id` int(11) NOT NULL,
  `name` longtext COLLATE utf8_unicode_ci NOT NULL,
  `firmAddress` longtext COLLATE utf8_unicode_ci NOT NULL,
  `postAddress` longtext COLLATE utf8_unicode_ci NOT NULL,
  `address` longtext COLLATE utf8_unicode_ci NOT NULL,
  `phone` longtext COLLATE utf8_unicode_ci NOT NULL,
  `email` longtext COLLATE utf8_unicode_ci NOT NULL,
  `inn` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `okpo` longtext COLLATE utf8_unicode_ci NOT NULL,
  `okvd` longtext COLLATE utf8_unicode_ci NOT NULL,
  `bankName` longtext COLLATE utf8_unicode_ci NOT NULL,
  `depositNumber` longtext COLLATE utf8_unicode_ci NOT NULL,
  `corrNumber` longtext COLLATE utf8_unicode_ci NOT NULL,
  `bik` longtext COLLATE utf8_unicode_ci NOT NULL,
  `regional_office_id` int(11) DEFAULT NULL,
  `doverennost` longtext COLLATE utf8_unicode_ci,
  `nalog_svid` longtext COLLATE utf8_unicode_ci,
  `firm_svid` longtext COLLATE utf8_unicode_ci,
  `nalog_uved` longtext COLLATE utf8_unicode_ci,
  `rospotreb_uved` longtext COLLATE utf8_unicode_ci,
  `vipiska` longtext COLLATE utf8_unicode_ci,
  `deleted` tinyint(1) DEFAULT NULL,
  `office_doc` longtext COLLATE utf8_unicode_ci,
  `date_create` datetime DEFAULT NULL,
  `director_fio` longtext COLLATE utf8_unicode_ci,
  `basis` int(11) DEFAULT NULL,
  `doverenost_number` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `doverenost_date` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `director_type` int(11) DEFAULT NULL,
  `ogrn_number` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `contract_type` int(11) DEFAULT NULL,
  `kpp` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `uniq_key` varchar(11) COLLATE utf8_unicode_ci NOT NULL,
  `comment` longtext COLLATE utf8_unicode_ci,
  `company_id` int(11) DEFAULT NULL,
  `is_new` tinyint(1) DEFAULT NULL,
  `director_fio_r` longtext COLLATE utf8_unicode_ci,
  `user_company` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `user_city` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `user_username` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `deleted_user_id` int(11) DEFAULT NULL,
  `deleted_date` datetime DEFAULT NULL,
  `admin_comment` longtext COLLATE utf8_unicode_ci,
  `momentAcceptText` longtext COLLATE utf8_unicode_ci,
  `auto_accept_id` int(11) DEFAULT NULL,
  `auto_accept_date` datetime DEFAULT NULL,
  `agency_id` int(11) DEFAULT NULL,
  `office_city_id` int(11) DEFAULT NULL,
  `region_id` int(11) DEFAULT NULL,
  `refused_code` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `refused_code_expired_at` datetime DEFAULT NULL,
  `removed_regional_office` int(11) DEFAULT NULL,
  `new_legal_office` int(11) DEFAULT NULL,
  KEY `IDX_D8698A764ACB6E9C` (`regional_office_id`),
  KEY `IDX_D8698A76979B1AD6` (`company_id`),
  KEY `IDX_D8698A76E93323CB` (`inn`),
  KEY `IDX_D8698A766B62DF18` (`date_create`),
  KEY `IDX_D8698A7657ED8D87` (`uniq_key`),
  KEY `IDX_D8698A76FDE969F2` (`deleted_user_id`),
  KEY `IDX_D8698A76B859ECB7` (`auto_accept_id`),
  KEY `IDX_D8698A76847CE637` (`director_type`),
  KEY `IDX_D8698A76CDEADB2A` (`agency_id`),
  KEY `idx_document_deleted` (`deleted`),
  CONSTRAINT `document2agency` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`id`),
  CONSTRAINT `FK_D8698A764ACB6E9C` FOREIGN KEY (`regional_office_id`) REFERENCES `regional_office` (`id`),
  CONSTRAINT `FK_D8698A76847CE637` FOREIGN KEY (`director_type`) REFERENCES `document_director_type` (`id`),
  CONSTRAINT `FK_D8698A76979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`),
  CONSTRAINT `FK_D8698A76B859ECB7` FOREIGN KEY (`auto_accept_id`) REFERENCES `user` (`id`),
  CONSTRAINT `FK_D8698A76FDE969F2` FOREIGN KEY (`deleted_user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

1 个答案:

答案 0 :(得分:0)

这不仅仅是因为primary key。即使你已经删除了主键;从您的show create table语句中可以清楚地看出,您对列有KEYUNIQUE KEY约束(如下所示),并且由于您正在获取该重复条目错误导致已经使用{492 1}}现在。

  KEY `IDX_D8698A764ACB6E9C` (`regional_office_id`),
  KEY `IDX_D8698A76979B1AD6` (`company_id`),
  KEY `IDX_D8698A76E93323CB` (`inn`),