Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal: Proper way to drop a table for module update

Tags:

drupal

What is the proper way to drop a table using hook_update_N? I can't find docs on this. If I run update_sql($sql); in my hook--the sql being a drop statement--it reports a failure, even though checking the db, I can see that the table was dropped.

like image 972
Aaron Avatar asked Mar 25 '11 20:03

Aaron


2 Answers

You should be able to use db_drop_table() (or the Drupal 6 version here).

like image 53
jhedstrom Avatar answered Oct 07 '22 01:10

jhedstrom


You can do it in hook_update_N

/**
 * Drop 'my_table' table.
 */
function MYMODULE_update_7001() {
  if (db_table_exists('my_table')) {
    db_drop_table('my_table');
  }
}
like image 32
milkovsky Avatar answered Oct 07 '22 00:10

milkovsky