Support Forum
Support › MB Custom Table › New columns not being added to already existing tablesResolved
I have a few new additions to an existing website created using custom tables.
The issue I'm having is that the new table columns arn't being added to the database.
Metabox:
$meta_boxes[] = array(
'id' => 'open_day',
'title' => 'Open Day',
'post_types' => array( 'academy' ),
'autosave' => false,
'context' => 'after_title',
'priority' => 'high',
'storage_type' => 'custom_table', // Important
'table' => "{$db_prefix}academies", // Your custom table name
'fields' => array(
array(
'name' => "Set the start and end date!",
'type' => "heading",
'columns' => 3,
),
// DATE
array(
'name' => 'Start Date',
'id' => "{$prefix}open_day_start_date",
'type' => 'date',
// jQuery date picker options. See here http://api.jqueryui.com/datepicker
'js_options' => array(
'appendText' => '(dd-mm-yyyy)',
'dateFormat' => 'dd-mm-yy',
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
'columns' => 4,
),
// DATE
array(
'name' => 'End Date',
'id' => "{$prefix}open_day_end_date",
'type' => 'date',
// jQuery date picker options. See here http://api.jqueryui.com/datepicker
'js_options' => array(
'appendText' => '(dd-mm-yyyy)',
'dateFormat' => 'dd-mm-yy',
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
),
'columns' => 5,
),
// CHECKBOX LIST
array(
'name' => 'Apply to:',
'id' => "{$prefix}academy_open_day_meridiem",
'type' => 'checkbox_list',
'inline' => 'true',
'options' => array(
'AM' => 'AM',
'PM' => 'PM',
'FR' => 'Friday',
),
),
),
);
Custom Table:
MB_Custom_Table_API::create( "{$db_prefix}academies", array(
"{$prefix}academy_notification_title" => 'TEXT NOT NULL',
"{$prefix}academy_notification_text" => 'TEXT NOT NULL',
"{$prefix}about_title" => 'TEXT NOT NULL',
"{$prefix}academy_description" => 'TEXT NOT NULL',
"{$prefix}academy_facebook" => 'TEXT NOT NULL',
"{$prefix}academy_twitter" => 'TEXT NOT NULL',
"{$prefix}principle_note_title" => 'TEXT NOT NULL',
"{$prefix}principle_description" => 'TEXT NOT NULL',
"{$prefix}academy_image" => 'TEXT NOT NULL',
"{$prefix}principle_popup_photo" => 'TEXT NOT NULL',
"{$prefix}principle_popup_title" => 'TEXT NOT NULL',
"{$prefix}principle_popup_description" => 'TEXT NOT NULL',
"{$prefix}academy_title" => 'TEXT NOT NULL',
"{$prefix}academy_address_line1" => 'TEXT NOT NULL',
"{$prefix}academy_address_line2" => 'TEXT NOT NULL',
"{$prefix}academy_address_town" => 'TEXT NOT NULL',
"{$prefix}academy_address_county" => 'TEXT NOT NULL',
"{$prefix}academy_address_postcode" => 'TEXT NOT NULL',
"{$prefix}academy_map" => 'TEXT NOT NULL',
"{$prefix}academy_opening_times_title_note" => 'TEXT NOT NULL',
"{$prefix}academy_meridiem" => 'TEXT NOT NULL',
"{$prefix}academy_opening_times" => 'TEXT NOT NULL',
"{$prefix}academy_find_us_title_note" => 'TEXT NOT NULL',
"{$prefix}academy_find_us_information" => 'TEXT NOT NULL',
"{$prefix}academy_contact_title_note" => 'TEXT NOT NULL',
"{$prefix}academy_contact_email" => 'TEXT NOT NULL',
"{$prefix}academy_contact_phone" => 'TEXT NOT NULL',
"{$prefix}meet_the_team_title" => 'TEXT NOT NULL',
"{$prefix}meet_the_team_group" => 'TEXT NOT NULL',
"{$prefix}noticeboard_group" => 'TEXT NOT NULL',
"{$prefix}footer_gallery" => 'TEXT NOT NULL',
"{$prefix}open_day_start_date" => 'TEXT NOT NULL',
"{$prefix}open_day_end_date" => 'TEXT NOT NULL',
"{$prefix}academy_open_day_meridiem" => 'TEXT NOT NULL',
"{$prefix}academy_video_url" => 'TEXT NOT NULL',
"{$prefix}academy_video_placeholder" => 'TEXT NOT NULL',
));
Hi, you need to call MB_Custom_Table_API::create
on init
hook or some hook. Do not call this only once when activate a plugin or a theme. The plugin auto detects the new table structure and upgrade it.