Community Documentation

hook_schema_alter

6 core.php hook_schema_alter(&$schema)
7 system.api.php hook_schema_alter(&$schema)
8 system.api.php hook_schema_alter(&$schema)

Performs alterations to existing database schemas.

When a module modifies the database structure of another module (by changing, adding or removing fields, keys or indexes), it should implement hook_schema_alter() to update the default $schema to take its changes into account.

See hook_schema() for details on the schema definition structure.

Parameters

$schema: Nested array describing the schemas for all modules.

Return value

None.

Related topics

File

developer/hooks/core.php, line 717
These are the hooks that are invoked by the Drupal core.

Code

<?php
function hook_schema_alter(&$schema) {
  // Add field to existing schema.
  $schema['users']['fields']['timezone_id'] = array(
    'type' => 'int', 
    'not null' => TRUE, 
    'default' => 0, 
    'description' => 'Per-user timezone configuration.',
  );
}
?>

Comments

Hi, Thanks for the

Hi,

Thanks for the suggestion, I tried this code

function bunit_id_schema_alter(&$schema) {
// Change datatype from INT to BIGINT for the field field_bunit_identity_number_value.
$schema['content_type_benificiary']['fields']['field_bunit_identity_number_value'] = array(
'type' => 'int',
'size'=>'big',
'not null' => FALSE,
);
}

Nothing Happened .... Is there any other way to change the data types ?

To the above poster: The name

To the above poster:

The name hook_schema_alter() is a little misleading in that it won't actually alter the schema of the database by making changes. Rather it is used for 'reporting' changes that have been made by a module to other module's tables. This allows certain functions (such as drupal_write_record()) to get an accurate schema definition when one module changes another's tables.

Login or register to post comments