Reputation:
I'm working on a script that sadly I inherited - with no commenting or anything. Argh! For testing purposes I duplicated one of the tables in the database which had an auto-incrementing ID. When the data is saved to the database, though, the ID number just reads "0" -- which is the default for that column. I'm not sure why it's not auto increasing anymore... any thoughts? Thank you!
Upvotes: 0
Views: 1228
Reputation: 545985
It sounds like your column isn't actually auto_increment
any more. This has happened to me a couple of times because there was a bug (?) in phpMyAdmin which I used to create backups: it wouldn't add the auto_increment
keyword into the CREATE TABLE statements. That was a massive pain in the butt...
Upvotes: 0
Reputation: 39583
Just to double check use the sql statement to show the show create table syntax for both tables and compare.
show create table <table>
Upvotes: 1
Reputation:
Did you create the new table from scratch or as a real copy? If the column is supposed to auto increment it should be a primary (or at least a unique) key, with no default value.
Upvotes: 2
Reputation: 86805
Are you sure you set the field in the duplicate table to auto-increment? Try running:
ALTER TABLE `duplicate_table` CHANGE `ai_key` `ai_key` INT( key_length ) NOT NULL AUTO_INCREMENT
And see if it is set or not.
Upvotes: 4