You are here

public function Table::dropUniqueKey in Data 8

Drop a unique key from a table.

Throws

DataException

File

src/Table.php, line 352

Class

Table
Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.

Namespace

Drupal\data

Code

public function dropUniqueKey($field) {
  $success = \Drupal::database()
    ->schema()
    ->addUniqueKey($this->name, $field);
  if ($success) {
    $schema = $this->table_schema;
    unset($schema['unique keys'][$field]);
    $this
      ->update(array(
      'table_schema' => $schema,
    ));
    drupal_get_schema($this->name, TRUE);
    return;
  }
  throw new DataException(t('Error dropping unique key.'));
}