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


] => 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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s