I want to add a column to a database by using hook_update_N(), but it should be 3rd column instead of last column. How I can achieve that please help in this regard. I tried to add weight but not working. below is my code which is creating a column at the last in the existed table.

function test_update_7001() {
  $column3 = array(
    'type' => 'varchar',
    'length' => 256,
    'not null' => FALSE,
    'weight' => 3,
  db_add_field('test_table', 'column3', $column3);

1 Answer 1


db_add_field doesn't support AFTER, which you would need to create your desired query.

You'll need to build an appropriate SQL string and run it through db_query() instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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