帝国cms教程

帝国CMS后台添加信息报错Duplicate entry 'xx' for key 'PRIMARY'

我的站长站 2020-09-14 人阅读

帝国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:后台修复数据库

如果进的了后台尝试后台修复数据库,点击 后台 系统 备份与恢复数据 备份数据

帝国CMS后台添加信息报错Duplicate entry 'xx' for key 'PRIMARY'

拉到最下面 点击修复数据表和优化数据表即可

帝国CMS后台添加信息报错Duplicate entry 'xx' for key 'PRIMARY'

方法2:插入一个大于当前索引的信息

如果后台修复没有用,那我们就来手动或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, '企业11111', 1333244427, '', 0, 1, 1350716513, 0, 0, 0, 0, '', '企业理念:诚信、专业、高效 星兴财务rn', 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;


相关推荐
  • 帝国CMS报错
  • Table 'XX.***_enewspubtemp_2' doesn't exist错误详解

    我的站长站测试帝国CMS在恢复数据库的时候,有时候会以下报错。Table 'px.***_enewspubtemp_2' doesn't existselect indextemp from ***_enewspubtemp_2 limit 1我们首先去看下数据库phome_enewspubtemp是什么表,enewspubtemp为公共模板表...

    帝国cms教程 257 3年前
  • 帝国CMS报错Fatal error: Maximum execution time of

    帝国CMS有时候可能会提示Fatal error: Maximum execution time of …错误,出现这个问题的原因是php运行超时,解决办法如下:去帝国后台参数设置那里把每组备份(刷新)数改小一点,或者去服务器里面把php.ini文件中的max_execution_t= 的值改大一点,如果文件...

    帝国cms教程 79 6年前
  • 帝国CMS数据库报错Parse error: syntax error, unexpected $end in的修复方法

    我的站长站准备修复一些网络上的精品老模板,在升级的时候遇到报错Parse error: syntax error, unexpected $end in D:\TDDOWNLOAD\zhao\e\admin\ebak\bdata\empirecms_20110413031059\phome_ecms_news_data_1_12.php on line 20网上找了一下...

    帝国cms教程 180 3年前
最新更新