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.
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.
Share Improve this question asked May 11, 2016 at 6:01 user1235285user1235285 1531 gold badge3 silver badges10 bronze badges 10 | Show 5 more comments2 Answers
Reset to default 6OK. 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!
Today I found a new possibility for this error. I was trying to add the category Butter to a recipe site. After 5 tries, I tried an experiment. I went directly to the database and tried changing the name of an unused category to Butter.
My results were that it was a database issue, not either a software limit or a software problem. The database error was more specific in that it told me that the slug "butter" was already being used for a different type of taxonomy. In this particular case, my look at the database showed that a plugin is adding all kinds of taxonomy terms.
The fix was that instead of using the slug "butter", I used "butter-ingredient" and the Category was added with no problems.
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 Commented May 11, 2016 at 6:09ALTER TABLE wp_terms AUTO_INCREMENT = X
but take the highest ID inwp_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 Commented May 11, 2016 at 6:16