1

This question already has an answer here:

I have a custom module already installed, and I am trying to add a new table to the database with hook_update_N(). So, I edited hook_schema() and hook_update_N() in the my_module.install file as below.

function my_module_schema() {
  $schema['my_table'] = array(
    'fields' => array(
      'application_setup_id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: ID',
      ),
    ),
    'primary key' => array('application_setup_id'),
  );
  return $schema;
}

function my_module_update_8601(&$sandbox) {
  $spec = array(
    'fields' => array(
      'application_setup_id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: ID',
      ),
    ),
    'primary key' => array('application_setup_id'),
  );
  $schema = Database::getConnection()->schema();
  $schema->createTable('my_table', $spec);
}

I am running drush updatedb to update the database after the changes. No database changes are done.

What am I missing?

marked as duplicate by mradcliffe, kenorb, Community Nov 13 '18 at 19:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Is it supposed to be 8601 or 8101? Check the documentation. api.drupal.org/api/drupal/… – Kevin Oct 24 '18 at 15:27
  • 2
    drupal_get_installed_schema_version('module_name') will get you the info you're looking for – Clive Oct 24 '18 at 15:29
  • my Drupal version is 8.6.2 when I check in admin/reports/status .I tried changing N to 8001,8101,8201,8701. when I run dpm(drupal_get_installed_schema_version('my_module')); in devel I am getting 8000. – user3324848 Oct 24 '18 at 16:09
  • my module name is using camel case, I changed it to lower case in the function name for hook_update_n and tried still didn't work. – user3324848 Oct 24 '18 at 16:18
  • There sounds like theres a lot wrong here. This is a core function that has worked for many versions, why you can't get it to trigger... I don't think there is enough information here. – Kevin Oct 24 '18 at 17:27

Browse other questions tagged or ask your own question.