I've spent a fair while reading about the "Could not insert term into the database" error, but the fixes I have read (changing theme, fresh WP install, disable plugins) simply are not working.

I tried a force DB upgrade, still no joy.

Looking at wp_terms there's a category with term_id of 0. This is mighty strange and if I delete it, I'm then able to add a category via wp-admin. However, subsequent categories then fail with the "Could not insert term into the database" message and re-checking wp_terms shows the freshly added category as id 0! This seems to suggest WP is assigning the cat a term_id of 0 every time.

Has anyone seen this? Any ideas on a fix? The database in question is pretty huge, so a rebuild would not be a pretty thing.

  • There is no code. I'm simply adding at category via /wp-admin/edit-tags.php?taxonomy=category – user1235285 May 11 '16 at 6:04
  • 1
    You should try ALTER TABLE wp_terms AUTO_INCREMENT = 1 then. Please note that it will set auto increment to 1, which means that you will need to re-enter every term you have in that table or any other term and taxonomy related tables. It will probably break the connections. Safest way would be to delete all the terms and taxonomies from admin area and then run this code in SQL from phpMyAdmin. Repeat this code with every table related to taxonomies and terms (just change the table name in code). – N00b May 11 '16 at 6:09
  • 1
    Or do you need to keep current terms and taxonomies? Maybe we can figure out something else. – N00b May 11 '16 at 6:10
  • Keeping the current terms would be best for sure. Any ideas? – user1235285 May 11 '16 at 6:13
  • 1
    Okay.. Other way would be to use the same code: ALTER TABLE wp_terms AUTO_INCREMENT = X but take the highest ID in wp_terms table, add 1 to it (e.g highest ID is 83, add 1 to it and you get 84) replace the X with that value (84 in our example). Do not forget to backup your database if data is important! – N00b May 11 '16 at 6:16

OK. There where multiple issues here;

wp_terms, wp_termmeta and wp_term_taxonomy all had their ID's set not to AUTO_INCREMENT.

Changing these and removing the 0 values from each table seems to have resolved this - very odd though.

Big thanks to @N00b for helping!

Not the answer you're looking for? Browse other questions tagged or ask your own question.