function db_add_unique_key
Same name in other branches
- 7.x includes/database/database.inc \db_add_unique_key()
Adds a unique key.
Parameters
$table: The table to be altered.
$name: The name of the key.
array $fields: An array of field names.
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 addUniqueKey() on it. For example, $injected_database->schema()->addUniqueKey($table, $name, $fields);
See also
https://www.drupal.org/node/2993033
\Drupal\Core\Database\Schema::addUniqueKey()
Related topics
1 call to db_add_unique_key()
- DatabaseLegacyTest::testDbAddUniqueKey in core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseLegacyTest.php - Tests deprecation of the db_add_unique_key() function.
File
-
core/
includes/ database.inc, line 964
Code
function db_add_unique_key($table, $name, $fields) {
@trigger_error('db_add_unique_key() 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 addUniqueKey() on it. For example, $injected_database->schema()->addUniqueKey($table, $name, $fields). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
return Database::getConnection()->schema()
->addUniqueKey($table, $name, $fields);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.