Skip to main content
addressed @Otto's answer
Source Link
shea
  • 5.6k
  • 4
  • 38
  • 62

As far as I know, dbDelta() is onlyprimarily used to add tables to the database. ToIt can also add, remove or change 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" );

As far as I know, dbDelta() is only used to add tables to the database. To add, remove or change columns you should use $wpdb->query():

global $wpdb;
$table = $wpdb->prefix . 'table_name';
$wpdb->query( "ALTER TABLE $table DROP COLUMN column_name" );

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" );
Source Link
shea
  • 5.6k
  • 4
  • 38
  • 62

As far as I know, dbDelta() is only used to add tables to the database. To add, remove or change columns you should use $wpdb->query():

global $wpdb;
$table = $wpdb->prefix . 'table_name';
$wpdb->query( "ALTER TABLE $table DROP COLUMN column_name" );