diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 85980e5..f48bf3d 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -1416,13 +1416,18 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st // NULL. unset($keys['label'], $keys['revision']); - // Only key fields may not be NULL, all the other columns have to be able - // to be NULL regardless of the actual field storage schema in order to - // support adding a base field definition to an entity type with non-empty - // base table(s). + // Key fields may not be NULL. + if (in_array($field_name, $keys)) { + $schema['fields'][$schema_field_name]['not null'] = TRUE; + } + // All the other columns have to be able to be NULL regardless of the + // actual field storage schema in order to support adding a base field + // definition to an entity type with non-empty base table(s). // @todo Revisit the strict 'not null' => FALSE requirement for all // non-key columns in https://www.drupal.org/node/2346019. - $schema['fields'][$schema_field_name]['not null'] = in_array($field_name, $keys) ? TRUE : FALSE; + elseif (isset($schema['fields'][$schema_field_name]['not null'])) { + $schema['fields'][$schema_field_name]['not null'] = FALSE; + } } if (!empty($field_schema['indexes'])) { diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php index 788744f..470a8b9 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php @@ -222,6 +222,7 @@ public function testGetSchemaBase() { 'columns' => array( 'target_id' => array( 'type' => 'int', + 'not null' => TRUE, ), 'target_revision_id' => array( 'type' => 'int', @@ -317,6 +318,7 @@ public function testGetSchemaBase() { 'editor_revision__target_id' => array( 'description' => 'The editor_revision field.', 'type' => 'int', + 'not null' => FALSE, ), 'editor_revision__target_revision_id' => array( 'description' => 'The editor_revision field.',