Auto_Increment在MySQL Server中不起作用 [英] Auto_Increment not working in MySQL Server

查看:517
本文介绍了Auto_Increment在MySQL Server中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我进入ASP.NET中的一个应用程序,该应用程序使用MySQL存储和获取数据以生成定义的报告.出现的问题是我第一次见到MySQL服务器&即Auto_Increment功能不起作用.我创建了一个具有简单架构的表:

Hi everyone,

I''m on to an app in ASP.NET which uses MySQL to store and fetch data from in order to generate a defined report. The problem that arrives is the first time I''ve come to see with MySQL server & that is Auto_Increment feature is not working. I''ve created a table with a simple Schema:

CREATE TABLE `worklog` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user` varchar(20) NOT NULL,
  `our_company` varchar(30) NOT NULL,
  `marketplace` varchar(30) NOT NULL,
  `pending_mails` int(11) NOT NULL DEFAULT '0',
  `ip` varchar(15) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1



现在的问题是,每当我尝试在此表中插入一条记录时,它就会显示错误-"id列的重复条目".我传递了DEFAULT参数以插入id,ts列的语句. MySQL服务器每次都将DEFAULT设为0(零),但不能这样.每次应将其递增1(因为默认情况下auto_increment值为1,但我尚未更改).我一直无法弄清楚是什么能使我摆脱这一困境.我尝试截断该表,设置Auto_Increment = 0,删除表并重新创建它.任何人....请建议我摆脱这种情况的正确方法.


问候,
Sunny



Now the problem is whenever I''m trying to insert a record in this table, it shows an error -"duplicate entry for id column". I''m passing DEFAULT parameter to insert statement for id,ts columns. MySQL server takes a 0 (zero) every time for DEFAULT which must not be like this. It should be incremented each time by 1 (since by default the auto_increment value is 1 and I haven''t changed it). I''ve just been unable to figure out what could get me rid of this. I''ve tried truncating this table, setting Auto_Increment=0, dropping table and recreating it. Anybody.... please suggest me the right way to get rid out of this.


Regards,
Sunny

推荐答案

在表中插入记录时,请勿插入id和ts列.即
When you insert a record into the table, do not insert columns id and ts. I.e.
Insert Into worklog (`user`, our_company, marketplace, pending_mails, ip) Values (...)


这篇关于Auto_Increment在MySQL Server中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆