function db_field_set_default

Same name in other branches
  1. 7.x includes/database/database.inc \db_field_set_default()

Sets the default value for a field.

Parameters

$table: The table to be altered.

$field: The field to be altered.

$default: Default value to be set. NULL for 'default NULL'.

Deprecated

in drupal:8.0.0 and is removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema() ->changeField($table, $field, $field_new, $spec, $keys_new);

See also

https://www.drupal.org/node/2993033

\Drupal\Core\Database\Schema::changeField()

Related topics

1 call to db_field_set_default()
DatabaseLegacyTest::testDbFieldSetDefault in core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php
Tests deprecation of the db_field_set_default() function.

File

core/includes/database.inc, line 874

Code

function db_field_set_default($table, $field, $default) {
    @trigger_error('db_field_set_default() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
    return Database::getConnection()->schema()
        ->fieldSetDefault($table, $field, $default);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.