Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5540

missing wp_download_log table due to MySQL issue with DATETIME field default val

$
0
0

I have identified a small issue that was preventing download logs from being kept on my installation.

When installed, the plugin creates a table with the following command (from mysql.log):


CREATE TABLE <code>wp_download_log</code> (
          ID bigint(20) NOT NULL auto_increment,
          type varchar(200) NOT NULL default 'download',
          user_id bigint(20) NOT NULL,
          user_ip varchar(200) NOT NULL,
          user_agent varchar(200) NOT NULL,
          download_id bigint(20) NOT NULL,
          version_id bigint(20) NOT NULL,
          version varchar(200) NOT NULL,
          download_date datetime NOT NULL default '0000-00-00 00:00:00',
          download_status varchar(200) NULL,
          download_status_message varchar(200) NULL,
          PRIMARY KEY  (ID),
          KEY attribute_name (download_id)
        ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci

On my development machine, an Ubuntu with MySQL VERSION() 5.7.16-0ubuntu0.16.04.1-log the default value for download_date is not allowed. So the table was never created. Fortunately the plugin still worked but I was getting the following error in the logs when a download was being made:

PHP message: WordPress database error Table 'wp_dev.wp_download_log' doesn't exist for query SHOW FULL COLUMNS FROM 'wp_download_log' made by require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array, DLM_Download_Handler->handler, DLM_Download_Handler->trigger, DLM_Download_Handler->log, DLM_Logging->create_log

What I did was I went and created the table manually, substituting 0000-00-00 00:00:00 with CURRENT_TIME. Now the table is being populated correctly on every download hit.

Incidentally, CURRENT_TIME is NOT a valid default value for DATETIME fields on my Debian machine, with version 5.5.52-0+deb8u1 . This feature was added in MySQL 5.6.5 for DATETIME fields. Also, that particular collation was not available on that machine so I had to leave it out.

Just pointing this out in case it’s something that can be fixed in a future version. I have already solved the issue for myself.

Thanks for taking the time to read. Apologies if it’s already fixed.


Viewing all articles
Browse latest Browse all 5540

Trending Articles