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 ?

2 s
2

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" );

Leave a Reply

Your email address will not be published. Required fields are marked *