Damon Cortesi's blog

Musings of an entrepreneur.

MySQL AUTO_INCREMENT Oops

| Comments

Well that was annoying. I was messing with the primary auto_increment key on one of my tables and set it to “-1”. Little did I know that when you specify a value for an auto_increment column, MySQL sets the next auto index to MAX(auto_increment_column)+1). Well, when you use “-1” in an unsigned column, the next auto index value turns out to be the max value for that column. That means that you can’t insert any more rows into that table! Oops!

The fix, referenced on mysql.com is simply to use the following command:

1
ALTER TABLE tbl_name AUTO_INCREMENT = value

where value is the auto index value you want to use.

I suppose that’s what I get for editing primary keys…

Comments