Click here to Skip to main content
14,669,375 members
Rate this:
Please Sign up or sign in to vote.
See more:
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


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
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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 (...)
   
Comments
Mehdi Gholam 31-Aug-12 2:30am
   
5'ed
Sunny_Kumar_ 31-Aug-12 2:40am
   
Thank you so much Mr. Hiller, you really saved my day! I really appreciate!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100