function Schema::validatePrimaryKeySchema
Validates a primary key schema definition.
Parameters
KeyColumns $key_fields: An array containing the fields that will form the primary key.
TableColumns $fields: (Optional) An array containing the field specifications of the table, as per the schema data structure format.
Throws
\Drupal\Core\Database\SchemaException If the specified fields fail validation.
12 calls to Schema::validatePrimaryKeySchema()
- Schema::addField in core/
modules/ sqlite/ src/ Driver/ Database/ sqlite/ Schema.php - Add a new field to a table.
- Schema::addField in core/
modules/ mysql/ src/ Driver/ Database/ mysql/ Schema.php - Add a new field to a table.
- Schema::addField in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php - Add a new field to a table.
- Schema::addPrimaryKey in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php - Add a primary key.
- Schema::addPrimaryKey in core/
modules/ mysql/ src/ Driver/ Database/ mysql/ Schema.php - Add a primary key.
File
-
core/
lib/ Drupal/ Core/ Database/ Schema.php, line 435
Class
- Schema
- Provides a base implementation for Database Schema.
Namespace
Drupal\Core\DatabaseCode
protected function validatePrimaryKeySchema(array $key_fields, array $fields = []) : void {
// Partial column lengths are only allowed on indexes.
foreach ($key_fields as $key_field) {
if (is_array($key_field)) {
@trigger_error('Specification of primary key with column length is deprecated in drupal:12.1.0 and will throw a SchemaException from drupal:13.0.0. Specify full columns for a primary key, or use an index for columns with partial length. See https://www.drupal.org/node/3375071', E_USER_DEPRECATED);
break;
}
}
// Primary key columns must be NOT NULL.
foreach (array_intersect($this->fieldNames($key_fields), array_keys($fields)) as $field_name) {
if (!isset($fields[$field_name]['not null']) || $fields[$field_name]['not null'] !== TRUE) {
throw new SchemaException("The '{$field_name}' field specification does not define 'not null' as TRUE.");
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.