Skip to main content
10 votes
Accepted

Fatal error: Call to undefined function dbDelta()

You answered your own question. You need to include the upgrade.php file which contains that function. Otherwise won't be loaded on your plugin update and the function won't exist. require_once(...
chifliiiii's user avatar
  • 2,852
9 votes

dbDelta only creates the last table

For those trying to understand how some plugins, like WooCommerce, are able to do that without calling dbDelta for every table, the reason is the IF NOT EXISTS part of query. The dbDelta function ...
Felipe Elia's user avatar
4 votes

dbDelta ALTER TABLE syntax?

To add column to some WP table in DB, you could use $wpdb for it: global $wpdb; $table = $wpdb->prefix . 'my_table'; $sql = "ALTER TABLE `{$table}` ADD `new_column` VARCHAR(20) NULL ...
burlakvo's user avatar
4 votes
Accepted

dbDelta does not create Table, but returns success

The Problem was in this line: time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, I changed it to: time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, Now, it works.
user998163's user avatar
3 votes

dbDelta() Error - Incorrect index name '' for query ALTER TABLE

You need to give it a name as well. UNIQUE KEY rowid (rowid)
cowgill's user avatar
  • 1,082
2 votes
Accepted

How to update an existing table while updating plugin?

register_activation_hook() only attaches a function to run on activation of your plugin, not on updating. See the docs for full details, particularly this part: 3.1 : This hook is now fired only ...
Tim Malone's user avatar
  • 4,754
2 votes
Accepted

Adding a Table to the wordpress database

Try: function vw_postcode_checker_create_db () { global $wpdb; // Create Table Name $table_name = $wpdb->prefix . "vw_postcode_checker"; // Write Query to add table to database ...
shanebp's user avatar
  • 5,063
2 votes
Accepted

Create table with dbDelta,can't put any DEFAULT data

It appears as though you're altering the users table - this is a WordPress core table (if using the wp_ prefix) and this is probably not a good idea - create a separate table with an ID foreign key to ...
Gray's user avatar
  • 324
2 votes

dbDelta not adding additional columns in plugin database update

After trial and error, here is the code that works: function installer(){ include('installer.php'); } register_activation_hook( __file__, 'installer' ); //executes installer php when installing ...
Himanshu's user avatar
2 votes
Accepted

Why my query 'REPLACE INTO...' does not work?

The reason is due to this code inside dbDelta() : // Create a tablename index for an array ($cqueries) of queries. foreach ( $queries as $qry ) { if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $...
J.BizMai's user avatar
  • 870
1 vote

Issue with WordPress Plugin Activation Hook and Table Creation

Not sure if this helps but try doing this in the main plugin file: require plugin_dir_path(__FILE__).'inc/plugin-setting.php'; require plugin_dir_path(__FILE__).'inc/db.php'; // Register activation ...
WordPress Buddha's user avatar
1 vote
Accepted

CREATE TABLE with dbDelta does not create table

Found a couple of things and am including what I believe will work to correct your issue. (As an aside, you should try and simplify your initial attempts so you can isolate what works and what doesn'...
Tony Djukic's user avatar
  • 2,108
1 vote
Accepted

Unable to create new database table upon plugin activation using dbDelta

Here is an updated version of installer.php which does create the table when activating the plugin. A check has been added to see if the custom table exists before proceeding with the creation of the ...
Dave Romsey's user avatar
  • 17.8k
1 vote

Unable to create new database table upon plugin activation using dbDelta

Do you get any errors? Feels like it is just a SQL issue you have. Have you tested your SQL-query manually and see if it works? I use the following and it works, I also set and check table version ...
lejahmie's user avatar
  • 373

Only top scored, non community-wiki answers of a minimum length are eligible