• Resolved pepe

    (@pputzer)


    With the most recent update (6.0.1, I skipped 6.0.0), I get a failed query:

    WordPress database error Incorrect index name 'id' for query ALTER TABLE PREFIX_ewwwio_images ADD PRIMARY KEY ('id')

    (I replaced the backticks with ' for the sake of posting the error message.)

    This is a multisite installation with MariaDB. I assume the problem is that a UNIQUE KEY 'id' already exists for the table.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Shane Bishop

    (@nosilver4u)

    Do you know what version of MariaDB you are using? I think it shows that on the WP Site Health report if you don’t know it offhand.

    Thread Starter pepe

    (@pputzer)

    That would be 10.4.17.

    Plugin Author Shane Bishop

    (@nosilver4u)

    Drat, so that’s probably the MariaDB bug resurfacing. I’ll dig into it again and let you now what I find out.

    Plugin Author Shane Bishop

    (@nosilver4u)

    So, I finally had a workaround in version 6.0 that bypassed the bug in 10.4. But then realized the PRIMARY KEY bit of our table creation syntax was incorrect (for the dbDelta() function). This caused issues for MySQL 8.0, so I corrected that in 6.0.1, but the behavior of the core dbDelta() function then re-triggers the MariaDB 10.4 bug.
    A potential fix is to give the PRIMARY KEY a name, which I’ve added to the code on GitHub if you could please test it and see how that works for you: https://docs.ewww.io/article/73-update-from-github

    Thread Starter pepe

    (@pputzer)

    Unfortunately, 6.0.1.1 has not helped. It looks like dbDelta() ignores the primary key name:

    
    WordPress database error Incorrect index name 'id' for query ALTER TABLE <prefix>_ewwwio_images ADD PRIMARY KEY  ('id') 
    made by 
    ...
    ewww_image_optimizer_admin_init, 
    ewww_image_optimizer_upgrade, 
    ewww_image_optimizer_install_table, 
    dbDelta
    

    Edit: So I looked it up, it’s on purpose 😩:

    // Escape the index name with backticks. An index for a primary key has no name.
    $index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '"' . strtolower( $index_matches['index_name'] ) . '"';
    • This reply was modified 5 years, 3 months ago by pepe. Reason: Add dbDelta excerpt
    Plugin Author Shane Bishop

    (@nosilver4u)

    Yeah, I just got done testing it on a fresh install and noticed the same… drat!
    I’ll see if I can come up with anything else to get around the MariaDB bug.

    Plugin Author Shane Bishop

    (@nosilver4u)

    Alright, I’ve got a different approach this time, similar to the one that was working in 6.0, but without the breakage for MySQL 8. Grab a fresh copy and let me know if that works for you: https://docs.ewww.io/article/73-update-from-github

    Plugin Author Shane Bishop

    (@nosilver4u)

    I tested it on a Cloudways server with MariaDB 10.4.17 and didn’t get any errors in the logs, and the workaround appears to have functioned correctly. Still would be great to get confirmation on your end though.

    Thread Starter pepe

    (@pputzer)

    Looks good. There were a lot of ALTER TABLE queries on each site after the update (for each column), but I presume that was because they didn’t run earlier due to the error?

    Plugin Author Shane Bishop

    (@nosilver4u)

    If it’s the same ALTER statements as I get on my dev site, those are because MariaDB, and pretty much every version of MySQL prior to 8.0.19, display column widths for a “SHOW TABLES” query, even if none are defined.
    So WordPress tries to alter the columns to have no “display widths”, but doesn’t end up actually doing anything.

    Thanks for confirming the fix!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Incorrect index name ‘id’’ is closed to new replies.