function db_field_set_default in Drupal 8
Same name and namespace in other branches
- 6 includes/database.mysql-common.inc \db_field_set_default()
- 6 includes/database.pgsql.inc \db_field_set_default()
- 7 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 - Core systems for the database layer.
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);
}