A note on the dbDelta function

The dbDelta function documented at https://codex.wordpress.org/Creating_Tables_with_Plugins:

The dbDelta function examines the current table structure, compares it to the desired table structure, and either adds or modifies the table as necessary, so it can be very handy for updates (see wp-admin/upgrade-schema.php for more examples of how to use dbDelta)

except hat it does not work. Here is a real example when I tried to use it. I created a table using following command:

the table got created. But then I tried to update it using dbDelta

this is the result:

so $result = Array
(

[visitor_log(

] => Created table visitor_log(

)

whereas $wpdb->last_error = Table ‘visitor_log’ already exists

When I checked in mysql, the table is not modified in any way.

This entry was posted in Software and tagged . Bookmark the permalink.

Leave a comment