Jump to content

Recommended Posts

I have a databse with an auto incrementing primary key , called reservation_id.

 

the values in this field were auto incrementing fine. 1..2..3..and so on. I decided to make the reservation_id the same as my order number so I just edited the last entry to be somehing like 8427861, thinking the auto increment would juct increase from there...but now whenever I run an INSERT query, I get this error:

 

Error: Duplicate entry '127' for key 1 with query INSERT INTO reservations (package_id, user_id, ccnum, exp_date, avs, total, num_people) VALUES('5', '6', '4111111111111111', '0108', '123', '180', '3')

 

Any ideas???

 

James

Link to comment
https://forums.phpfreaks.com/topic/81802-broke-my-auto-increment/
Share on other sites

8427861 is just the highest number you can have.

So if you want to store another row, it can't increment the id.

 

just set your autoincrement value lower.

in for example phpmyadmin give the following SQL command

 

ALTER TABLE tbl_name AUTO_INCREMENT = ***

*** is the lowest value from wehere you want the id to increment.

 

 

just set your autoincrement value lower.

NO NO NO NO NO NO NO NO NO!

 

Don't make your auto-increment column TINYINT -- make it UNSIGNED INT (or BIGINT), and you'll be fine forever.

 

Don't set up a situation where your IDs can be resued -- that's EXACTLY why the DB won't let you do this!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.