• Introduction:
    Wordpress does not seem to check if database structure/scheme on existing sites is equal to how it would be on a new install.

    Questions

    • How can I check the validity & integrity of the WordPress core database structure/scheme to detect differences in how the tables are setup (think constraints etc.) and how it should be by default in the most recent version of WordPress?

    Description of problem
    When trying to add a category I receive the error:

    WordPress database error: [Duplicate entry ‘test’ for key ‘slug’] INSERT INTO wp_terms (name, slug, term_group) VALUES (‘Test’, ‘test’, 0)

    What seems to be the cause of the problem?
    My install does not allow a category (test) with the same slug as an existing tag (test). WordPress should allow this.

    On further investigation: in wp_terms table, the field slug has a UNIQUE constraint. This was changed in WordPress 4.1 three years ago.(Link to trac 22023

    Duplicates are now prevented in WordPress code instead of in the database, but it seems like my site has skipped one or more database updates.

    In short
    My install is up to date. But my database structure/scheme is not up to date. wp_repair, wp_optimize etc. do not flag this.

    I was able to fix this but potentially my database still has other undetected differences.

    Temporary fix
    I manually removed the index/UNIQUE constraint on the slug field in wp_terms in the database. I tested and validated that duplicate slugs can now be created, while still unique in each taxonomy. (tags/categories)

    I would love to hear your thoughts on this! Depending on feedback I might submit this as a bug.

Viewing 1 replies (of 1 total)
  • Tim Nash

    (@tnash)

    Spam hunter

    This certainly sounds like a bug or at least something that needs some usecase testing around so raising it on Trac is the place to go.

    • This reply was modified 6 years, 9 months ago by Tim Nash.
Viewing 1 replies (of 1 total)
  • The topic ‘Database update schema integrity question’ is closed to new replies.