db_add_field

Versions
6
db_add_field(&$ret, $table, $field, $spec, $new_keys = array())
7
db_add_field($table, $field, $spec, $keys_new = array())

Add a new field to a table.

See also

db_change_field()

Parameters

$table Name of the table to be altered.

$field Name of the field to be added.

$spec The field specification array, as taken from a schema definition. The specification may also contain the key 'initial', the newly created field will be set to the value of the key in all rows. This is most useful for creating NOT NULL columns with no default value in existing tables.

$keys_new Optional keys and indexes specification to be created on the table along with adding the field. The format is the same as a table specification but without the 'fields' element. If you are adding a type 'serial' field, you MUST specify at least one key or index including it in this array. See db_change_field() for more explanation why.

Related topics

▾ 18 functions call db_add_field()

aggregator_update_7000 in modules/aggregator/aggregator.install
Add hash column to aggregator_feed table.
comment_update_7007 in modules/comment/comment.install
Split {comment}.timestamp into {comment}.created and {comment}.changed.
comment_update_7008 in modules/comment/comment.install
Add language column to the {comment} table.
comment_update_7010 in modules/comment/comment.install
Add {node_comment_statistics}.cid column.
filter_update_7000 in modules/filter/filter.install
Add a weight column to the filter formats table.
filter_update_7004 in modules/filter/filter.install
Move filter settings storage into {filter} table.
hook_update_N in modules/system/system.api.php
Perform a single update. For each patch which requires a database change add a new hook_update_N() which will be called by update.php.
locale_update_7000 in modules/locale/locale.install
Add context field and allow longer location.
node_update_7005 in modules/node/node.install
Add status/comment/promote and sticky columns to the {node_revision} table.
poll_update_7002 in modules/poll/poll.install
Add timestamp field to {poll_votes}.
scaffolding_example_update_6100 in developer/examples/scaffolding_example/scaffolding_example.install
Implementation of hook_update_N().
system_update_6051 in modules/system/system.install
Create a signature_format column.
system_update_7008 in modules/system/system.install
Use the poll_choice primary key to record votes in poll_votes rather than the choice order. Rename chorder to weight.
system_update_7045 in modules/system/system.install
Add expiration field to the {flood} table.
taxonomy_update_7002 in modules/taxonomy/taxonomy.install
Add vocabulary machine_name column.
taxonomy_update_7006 in modules/taxonomy/taxonomy.install
Add vocabulary machine_name column.
update_fix_d7_requirements in includes/update.inc
Perform Drupal 6.x to 7.x updates that are required for update.php to function properly.
user_update_7004 in modules/user/user.install
Add the user's pictures to the {file} table and make them managed files.

Code

includes/database/database.inc, line 2401

<?php
function db_add_field($table, $field, $spec, $keys_new = array()) {
  return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.