プラグインに限った話ではないのですが、WordPressで独自のテーブルを作ろうとした時に「Index column size too large」というエラーが出て、テーブルが作れない場合があります。
MySQL(InnoDB)では、ひとつのカラムのキープレフィックスの最大値が767バイトという制限があるらしく、これに引っかかると上記のようなErrorが出るそう。
ということなので、対応。
設定の変更
まずは、my.cnfの見直し。以下のように設定変更。
[mysqld] innodb_file_format = Barracuda innodb_file_per_table = 1 innodb_large_prefix
テーブル作成クエリの見直し
クエリの最後に’ROW_FORMAT=DYNAMIC’を追加。
今回はNginx Cache ControllerのCREATE TABLEの時に発生したので、該当箇所を変更。
public function activation() { global $wpdb; if ($wpdb->get_var("show tables like '$this->table'") != $this->table) { $sql = "CREATE TABLE `{$this->table}` ( `cache_key` varchar(32) not null, `cache_id` bigint(20) unsigned default 0 not null, `cache_type` varchar(11) not null, `cache_url` varchar(256), `cache_saved` timestamp default current_timestamp not null, primary key (`cache_key`), key `cache_id` (`cache_id`), key `cache_saved`(`cache_saved`), key `cache_url`(`cache_url`), key `cache_type`(`cache_type`) ) ROW_FORMAT=DYNAMIC;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); update_option(self::OPTION_NAME_DB_VERSION, $this->version); } $this->add_caps(); }
とりあえず、これでErrorはなくなり、無事にテーブル作成できました。
これを行う場合、プラグインの中を編集してしまうので、自己責任でお願いします。m(__)m
参考
MySQL(InnoDB) で “Index column size too large. The maximum column size is 767 bytes.” いわれるときの対策