You are here

protected function Schema::ensureNotNullPrimaryKey in Drupal 8

Same name and namespace in other branches
  1. 9 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/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
Add a new field to a table.
Schema::addField in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Add a new field to a table.
Schema::addField in core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
Add a new field to a table.
Schema::addPrimaryKey in core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
Add a primary key.
Schema::changeField in core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
Change a field definition.

... See full list

File

core/lib/Drupal/Core/Database/Schema.php, line 732

Class

Schema
Provides a base implementation for Database Schema.

Namespace

Drupal\Core\Database

Code

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.");
    }
  }
}