Failed to execute query: Duplicate entry '0' for key 'PRIMARY'
2014-03-25 23:00
330 查看
版权声明:转载注明出处 https://blog.csdn.net/weixin_42514606/article/details/86161714
Failed to execute query: Duplicate entry '0' for key 'PRIMARY'
今天在做php登陆和登出会插入数据到log表中,,结果报错了:如下:
Failed to execute query: Duplicate entry '0' for key 'PRIMARY' SQL: INSERT INTO log set LOGID = 'IN', LOG01 ='test', LOG02 ='127.0.0.1', DT999 = now()
这说明每次往表中插入记录的PRIMARY值均为0
问题描述:
修改前表的结构;
SQL 查询结果 主机: localhost 数据库: minierp 生成日期: 2014 年 03 月 25 日 14:50 生成者: phpMyAdmin 2.10.3 / MySQL 6.0.4-alpha-community-log SQL 查询: show create table log; 行数: 1 Table Create Table log CREATE TABLE `log` ( `AUTOID` bigint(20) NOT NULL, `LOGID` varchar(20) NOT NULL DEFAULT '', `LOG01` varchar(20) NOT NULL DEFAULT '', `LOG02` varchar(40) NOT NULL DEFAULT '', `LOG03` varchar(40) NOT NULL DEFAULT '', `DT999` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`AUTOID`) ) ENGINE=InnoDB DEFAULT CHARSET=gbk COMMENT='操作记录表'
log表的status:
SQL 查询结果 主机: localhost 数据库: minierp 生成日期: 2014 年 03 月 25 日 14:52 生成者: phpMyAdmin 2.10.3 / MySQL 6.0.4-alpha-community-log SQL 查询: show table status like 'log'; 行数: 1 Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment log InnoDB 10 Compact 5 3276 16384 0 0 0 NULL 2014-03-25 22:15:39 NULL NULL gbk_chinese_ci NULL 操作记录表
其中Auto_increment-值为NULL;
解决办法就是把其关键之设置为自增!
解决问题思路:
1、老的表结构,使用的复合索引——“PRIMARY KEY (`AUTOID`)”,没有指定 auto_increment 的值; 2、删除原来主键,重新创建新主键时(alter table log add primary key(AUTOID); ),也未指定 auto_increment的值,所以在创建了新主键后,再看表 log 的状态时, Auto_increment 一栏的值仍为 NULL; 3、mysql 不支持 “alter table sg_medal_action add auto_increment primary key(action_id);”这样的语句,请详看 alter 的语法 http://dev.mysql.com/doc/refman/5.0/en/alter-table.html ; 4、解决问题 mysql> ALTER TABLE `log` CHANGE `AUTOID` `AUTOID` BIGINT( 20 ) NOT NULL AUTO_INCREMENT;
OK,问题解决了.
posted @ 2014-03-25 23:00 Rikies 阅读(...) 评论(...) 编辑 收藏
相关文章推荐
- 关于Failed to execute 'querySelectorAll' on 'Document': '#1517905886124' is not a valid selector."
- mysql主从库同步错误:1062 Error 'Duplicate entry '1438019' for key 'PRIMARY'' on query
- Uncaught SyntaxError: Failed to execute 'querySelectorAll' on 'Element': '#00' is not a valid select
- Failed to execute query: Duplicate entry '0' for key 'PRIMARY'
- Last_Errno: 1062,Last_Error: Error 'Duplicate entry '...' for key 'PRIMARY'' on query. 的详细分析过程
- 报错:Conversion to Dalvik format failed: Unable to execute dex:
- Maven项目报错:Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clea
- Ios9.0 canOpenURL: failed for URL: "xx" - error:"This app is not allowed to query for scheme xx"
- maven install Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war
- 【maven install报错】Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
- eclipse android程序运行报错:Conversion to Dalvik format failed: Unable to execute dex:
- 解决Failed to execute goal org.apache.maven.plugins
- "Failed to execute tools\android.bat"解决办法
- -canOpenURL: failed for URL: "wechat://" - error: "This app is not allowed to query for scheme wech
- Failed to execute goal on project taotao-sso: Could not resolve dependencies for project com.taotao:
- Conversion to Dalvik format failed: Unable to execute dex:
- Uncaught SecurityError: Failed to execute 'replaceState' on 'History':解决方案
- Server Application Unavailable 【Failed to execute request because the App-Domain could not be created.】的解决办法
- VS2010提示error TRK0002: Failed to execute command
- 针对Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解决方案