0

On plugin activation hook I want to create a table but the following code is giving Uncaught Error. I just wonder why it is not giving this error since I am properly including update.php.

global $wpdb;

$sql = 'CREATE TABLE IF NOT EXISTS '.$wpdb->prefix.'gs_orders(';
$sql .= 'id BIGINT(20) AUTO_INCREMENT NOT NULL,';
$sql .= 'order_number VARCHAR(200) NOT NULL,';
$sql .= 'group_id INT NOT NULL,';
$sql .= 'group_admin BIGINT(20) NOT NULL,';
$sql .= 'group_user BIGINT(20) NOT NULL,';
$sql .= 'product_groups VARCHAR(255),';
$sql .= 'products VARCHAR(255),';
$sql .= 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,';
$sql .= 'updated_at DATETIME NULL DEFAULT NULL,';
$sql .= 'PRIMARY KEY (id),';
$sql .= 'INDEX (order_number, group_id, group_admin, group_user),';
$sql .= ')' . $wpdb->get_charset_collate() . ';';

require_once ABSPATH . '/wp-admin/includes/update.php';
dbDelta($sql);

Above code is on the plugin activation callback function.

0

I was including the wrong file. Instead of update.php I should include upgrade.php. I know it's a silly mistake but maybe help someone who does the same in future.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.