WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a table using the dbDelta function and then removed a few columns and added a few. The new columns did get created but the old columns did not get deleted from the table.

Is there a different way I am supposed to delete columns from the table ?

share|improve this question
+1 was looking for the same answer :) – Sisir Nov 22 '14 at 7:51
up vote 6 down vote accepted

As far as I know, dbDelta() is primarily used to add tables to the database. It can also add or alter columns. To delete columns, you should use $wpdb->query():

global $wpdb;
$table = $wpdb->prefix . 'table_name';
$wpdb->query( "ALTER TABLE $table DROP COLUMN column_name" );
share|improve this answer
Not correct. dbDelta can, and does add columns. – cale_b Dec 21 '12 at 23:26
Sorry, @cale_b, I've updated my answer – shea Dec 21 '12 at 23:41

No, dbDelta can add or alter columns, but not drop them.

The code for the dbDelta function is in wp-admin/includes/upgrade.php. You can examine what it is capable of there.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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