dbDelta() Error – Incorrect index name ” for query ALTER TABLE
You need to give it a name as well. UNIQUE KEY rowid (rowid)
You need to give it a name as well. UNIQUE KEY rowid (rowid)
The above code should be placed in a function and then hook that with plugin activation hook? Here’s sample structure of plugin-name.php file. Note – Use CREATE TABLE IF NOT EXISTS instead only create table Code Updated on – 2012-08-04 <?php // this code goes into your my_plugin_name.php file function install_my_plugin() { global $wpdb; $table_name … Read more
Delete everything but wp-content and wp-config.php, copy the fresh installation into the directory. On upgrading WordPress will use the database to see what should be done, not the files. Not all files are deleted automatically, because some of them might still be used by outdated plugins or external scripts (the old feed files are good … Read more
Here’s an updated version of pf_rb_install(). In the table creation SQL, $table_name should not be in quotes. The quotes should have triggered an error which would appear in PHP’s error.log file. Also, there should be two spaces after the PRIMARY KEY (id) portion of the SQL statement. register_activation_hook( __FILE__, ‘pf_rb_install’ ); function pf_rb_install() { global … Read more
dbDelta is squirrelly. Some things it will alter, others it will not. For example, and if I remember correctly, you can add indexes to tables but not change those indexes or delete them. I honestly don’t know if it will remove table columns. (My guess it that it won’t but I may test that later.) … Read more
As @Charleston Software Associates mentioned, the DESCRIBE query should not be executed if the table doesn’t exist. The best solution, as he pointed out, is to prevent the error from occurring in the first place. To do so, patch wp-admin/includes/upgrade.php as follows: Change the following line from dbDelta(): $tablefields = $wpdb->get_results(“DESCRIBE {$table};”); to: //Begin core … Read more
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(ABSPATH . ‘wp-admin/includes/upgrade.php’);
You’ve used the dbDelta function incorrectly. The whole point of that function is you pass in a table creation SQL command. If the table doesn’t exist, it creates it. If the table exists but doesn’t match, it’s modified until it matches. This includes adding and updating columns, indexes, and other aspects. So what you want … Read more
As a general rule, dbDelta does not yet support FOREIGN KEY, though I’ve been told it works on MySQL 5.1 (I can confirm it doesnt work on MySQL 5.5).
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.