2015-01-15 202 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