帝國cms后臺添加信息報錯Duplicate entry 'xx' for key 'PRIMARY',出現以下代碼
Duplicate entry '3261' for key 'PRIMARY'insert into ***_ecms_news_index(classid,checked,newstime,truetime,lastdotime,havehtml) values('1','1','1446087639','1446087687','1446087687','1');
這種帝國CMS報錯是因為ecms_news_index索引數字不對,索引ID“3261”的信息已經存在,后添加的信息索引ID必須大于“3261”才行。
照成這種錯誤一般是后臺丟失數據,導致索引無法正常遞增混亂。
方法1:后臺修復數據庫如果進的了后臺嘗試后臺修復數據庫,點擊 后臺 系統 備份與恢復數據 備份數據
拉到最下面 點擊修復數據表和優化數據表即可
如果后臺修復沒有用,那我們就來手動或SQL插入一個大于“3261”等等信息,讓索引ID重新遞增。
手動操作直接參考數據庫的信息,ID填一個大于“3261”的即可。
SQL插入看下面代碼
INSERT INTO `phome_ecms_news` VALUES (3262, 1, 1, '', '', '', 1, 'admin', '', 1, 0, 1333244472, 0, 1, 0, 0, ',b|', '', '1', 0, 0, 0, 0, 0, 0, '帝國cms模板', 1333244427, '', 0, 1, 1350716513, 0, 0, 0, 0, '', '帝國cms模板網', 0, '1', '', 0, '', 0);
第一個字段“3262”就是索引ID,后面的參考自己的字段調整。
方法3:批量重新生成索引如果以上都不行,只能用SQL想辦法讓索引ID重新生成一遍,建議分條執行,一是避免超時,二是能發現錯誤
CREATE TABLE [!db.pre!]ecms_newstemp AS(SELECT id,classid,newstime,truetime,lastdotime,havehtml FROM [!db.pre!]ecms_news);ALTER TABLE `[!db.pre!]ecms_newstemp` ADD COLUMN `checked` tinyint(1) not null DEFAULT 0 AFTER `classid`;ALTER TABLE `[!db.pre!]ecms_newstemp` add primary key (id);alter table [!db.pre!]ecms_news_index rename to [!db.pre!]ecms_news_indexbak;alter table [!db.pre!]ecms_newstemp rename to [!db.pre!]ecms_news_index;ALTERTABLE`[!db.pre!]ecms_news_index`CHANGE`id``id`INT(10)NOTNULLAUTO_INCREMENT;alter table [!db.pre!]ecms_news_index add index(classid);alter table [!db.pre!]ecms_news_index add index(checked);alter table [!db.pre!]ecms_news_index add index(newstime);alter table [!db.pre!]ecms_news_index add index(truetime);update [!db.pre!]ecms_news_index set checked=1;
新聞熱點
疑難解答