2015-01-15 98 views
0

我有一个叫做document的表。当主键没有主键时,mysql主键重复输入

引擎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 
+0

即使我设置了foreign_key_cheks = 0,请发布'show create table document' – 2015-01-15 16:21:13

回答

0

这不仅仅是因为primary key。即使你已经丢弃了主键,从你的show create table声明很明显,你有KEYUNIQUE KEY约束列(如下所示),并因此你得到的重复条目错误原因已经是492存在的关键。

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

的输出吗? – Ahmed 2015-01-15 18:54:14

+0

是的,因为它与FK检查无关。这些是唯一的关键约束。您可以通过删除约束来完全禁用约束检查 - >执行INSERT,然后重新创建它们。 – Rahul 2015-01-18 11:24:40