Commit 08d3ebba authored by alexpott's avatar alexpott
Browse files

Issue #2232477 by tstoeckler, a 'fliptable' mateescu, plach: Fixed Fatal when...

Issue #2232477 by tstoeckler, a 'fliptable' mateescu, plach: Fixed Fatal when adding new fields with NOT NULL constraints in a base table that contains existing entities.
parent 4dc03e70
......@@ -1415,10 +1415,19 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st
// table. For this reason the revision ID field cannot be marked as NOT
// NULL.
unset($keys['label'], $keys['revision']);
// 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.
elseif (isset($schema['fields'][$schema_field_name]['not null'])) {
$schema['fields'][$schema_field_name]['not null'] = FALSE;
}
}
if (!empty($field_schema['indexes'])) {
......
......@@ -220,6 +220,7 @@ public function testGetSchemaBase() {
'columns' => array(
'target_id' => array(
'type' => 'int',
'not null' => TRUE,
),
'target_revision_id' => array(
'type' => 'int',
......@@ -315,6 +316,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.',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment