How should I insert a row into a database table created by another module? I'm attempting to insert a row into a table created by another module. This module was enabled in a previous hook_update_N(); I want to insert a row into the table with another hook_update_N() or the same one. Using two hook_update_N() works when the updates are ran at different times but if both updates are ran at once the second update fails because the table does not yet exist. I have tried using sleep() but that seems problematic.

/**
 * Enable commerce fees
 */
function mymodule_update_7004($node) {
  module_enable(array('commerce_fees'));
}

/**
 * create compliance fee
 */
function mymodule_update_7005($node) {
  // wait for commerce_fee table to be created
  sleep(10);
  if (db_table_exists('commerce_fees') == TRUE) {
      db_insert('commerce_fees')
    -&gt;fields(array(
      'name' =&gt; 'non_compliance_fee',
      'title' =&gt; 'Non-compliance Fee',
      'display_title' =&gt; 'Refundable Non-compliance Fee',
      'description' =&gt; '',
    ))
    -&gt;execute();

    // Clear the necessary caches and rebuild the menu items.
    commerce_fees_reset();
    entity_defaults_rebuild();
    menu_rebuild();
  }

  else {
    drupal_set_message('table commerce_fees does not exist');
  }
}
I recommend using DrupalUpdateException to make update 7005 fail if the table doesn't exist so that it can be ran again when the table has been added, or at least notify the web builder that the table doesn't exist and needs to be worked on.