Jump to content

Broke my Auto Increment??


jwwceo

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.