function Schema::ensureNotNullPrimaryKey
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::ensureNotNullPrimaryKey()
- 10 core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::ensureNotNullPrimaryKey()
- 11.x core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::ensureNotNullPrimaryKey()
Ensures that all the primary key fields are correctly defined.
Parameters
array $primary_key: An array containing the fields that will form the primary key of a table.
array $fields: An array containing the field specifications of the table, as per the schema data structure format.
Throws
\Drupal\Core\Database\SchemaException Thrown if any primary key field specification does not exist or if they do not define 'not null' as TRUE.
10 calls to Schema::ensureNotNullPrimaryKey()
- 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/ sqlite/ src/ Driver/ Database/ sqlite/ Schema.php - Add a primary key.
- Schema::changeField in core/
modules/ sqlite/ src/ Driver/ Database/ sqlite/ Schema.php - Change a field definition.
File
-
core/
lib/ Drupal/ Core/ Database/ Schema.php, line 698
Class
- Schema
- Provides a base implementation for Database Schema.
Namespace
Drupal\Core\DatabaseCode
protected function ensureNotNullPrimaryKey(array $primary_key, array $fields) {
foreach (array_intersect($primary_key, 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.