Entity update required / breaks with dev / alpha2

Created on 28 August 2018, over 6 years ago
Updated 16 December 2024, 2 days ago

This is a follow-up issue from #2959907: Update to alpha2 / dev not working with database prefixes for users who updated from a prevous version (no fresh install).
It has no logical connection to #2959907: Update to alpha2 / dev not working with database prefixes because that issue handles a problem with database prefixes.

Both handle update problems so they were combined before which may have lead to confunsion.

Problem / reproduction:

When upgrading from alpha1 (or earlier) to alpha2 token_custom_update_8001 runs cleanly. Anyway the status report shows:

Errors found:
Entity/field definitions
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Custom Token

The Content field needs to be updated.

Running "drush entup" (which should not be required on regular sites) fails with:

[error] Drupal\Core\Entity\EntityStorageException: Exception thrown while performing a schema update. SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content' in 'where clause': SELECT 1 AS expression
FROM
{token_custom_field_data} t
WHERE content IS NOT NULL
LIMIT 1 OFFSET 0; Array
(
)
in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() (line 1535 of /core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Proposed solution:

#2959907: Update to alpha2 / dev not working with database prefixes had a combined patch which contained

$connection = Database::getConnection();
  /* @var \Drupal\Core\Database\Schema */
  $schema = $connection->schema();
  /* @var \Drupal\Core\Entity\EntityTypeManagerInterface */
  $entity_type_manager = \Drupal::entityTypeManager();
  /* @var \Drupal\Core\Entity\EntityTypeInterface */
  $entity_type_definition = $entity_type_manager->getDefinition('token_custom');
  /* @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface */
  $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();

  $base_table = $entity_type_definition->getBaseTable();
  $field_data_table = $base_table . '_field_data';

  if ($entity_definition_update_manager->needsUpdates()) {
    if (!$schema->fieldExists($field_data_table, 'content')) {
      $schema->addField($field_data_table, 'content', [
        'type' => 'varchar',
        'description' => "Temporary field to fix entity update.",
        'length' => 255,
        'not null' => false,
      ]);
    }
    $entity_definition_update_manager->applyUpdates();
  }

Which fixes the problem and removes the requirement to run an entity update. But of course that code should only run if the entity update is required and not for clean installs.

🐛 Bug report
Status

Closed: outdated

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024