Support Forum
Support › MB Custom Table › Custom Tables - multiple issues
I just bought the MB plugin, and having issues while testing on a local site (Mamp Pro). Trying to test out MB Custom Tables, using this guide: https://docs.metabox.io/extensions/mb-custom-table/
I have the AIO bundle plugin installed, and all the add-ons checked off in the settings page. But in the Settings field of my first test metabox (using MB Builder), it isn't showing any settings for Custom Tables, instead it says "Requires MB Custom Table." with a link to buy the plugin. Is MB Custom Table not compatible with the Builder UI? Or does it have to be installed separate from the AIO plugin? Guessing it's something else...
I have the following code in an mu-plugin:
add_action( 'plugins_loaded', 'pxb_create_table' );
function pxb_create_table() {
if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
return;
}
MB_Custom_Table_API::create( 'my_new_table', array(
'address' => 'TEXT NOT NULL',
'phone' => 'TEXT NOT NULL',
'email' => 'TEXT NOT NULL',
) );
}
I can see the table is created in phpMyadmin, yet still on the Settings page I only see the message that MB Custom Tables is required. Why might this be?
And then another issue with Custom Tables:
If I try to add a custom key as described in your same guide like the following, I get PHP errors and it does not create the table.
add_action( 'plugins_loaded', 'prefix_create_table' );
function prefix_create_table() {
if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
return;
}
MB_Custom_Table_API::create( 'my_custom_table2', array(
'address' => 'TEXT NOT NULL',
'phone' => 'TEXT NOT NULL',
'email' => 'TEXT NOT NULL',
), array( 'email' ) );
}
The error message says:
WordPress database error BLOB/TEXT column 'email' used in key specification without a key length for query
Reading up on it, seems that mySQL can’t use a key that doesn’t have a specified length… I changed it to the following and it seems to work now.
'email' => 'VARCHAR(100) NOT NULL’,
Should you guys update that tutorial, or is there something odd going on with my setup?
Is the database type and/or collation a factor here? My db is type InnoDB and the collation is: utf8mb4_unicode_520_ci
[25-May-2018 15:39:21 UTC] WordPress database error BLOB/TEXT column 'email' used in key specification without a key length for query
CREATE TABLE my_custom_table (
<code>ID</code> int(11) unsigned NOT NULL,
<code>address</code> TEXT NOT NULL,
<code>phone</code> TEXT NOT NULL,
<code>email</code> TEXT NOT NULL,
PRIMARY KEY (<code>ID</code>),
KEY <code>email</code> (<code>email</code>)
) COLLATE utf8mb4_unicode_520_ci made by require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, prefix_create_table, MB_Custom_Table_API::create, dbDelta
Unrelated side note, but I also got TGM activation PHP errors during the initial install. Altogether not a good start with MB - but hoping these are due to something in my local config and not a typical experience?
[25-May-2018 15:16:21 UTC] PHP 12. Bulk_Upgrader_Skin->after() /.../wp-content/plugins/meta-box-aio/class-tgm-plugin-activation.php:3646