Auto growth stopped in MySQL?

I am working on a script which unfortunately I inherited - no comments or anything else. Argh! For testing purposes, I duplicated one of the tables in the database that had an auto-increment id. However, when the data is stored in the database, the ID simply reads "0" - this is the default for this column. I'm not sure why this is not increasing anymore ... any thoughts? Thank!

0


source to share


4 answers


Are you sure you are setting a field in the duplicate table to auto-increment? Try to run:

 ALTER TABLE `duplicate_table` CHANGE `ai_key` `ai_key` INT( key_length ) NOT NULL AUTO_INCREMENT  

      



And see if it's installed or not.

+4


source


Is the new table created from scratch or as a real copy? If a column is to grow automatically, it must be the primary (or at least unique) key with no default.



+2


source


Just double check using sql statement to show show create table syntax for both tables and compare.

show create table <table>

      

+1


source


It looks like your column is no longer auto_increment

. This happened to me a couple of times because there was a bug (?) In phpMyAdmin that I used to create backups: it didn't add a keyword auto_increment

to the CREATE TABLE statements. It was a huge pain in the butt ...

0


source







All Articles