πŸ‡ΊπŸ‡ΈUnited States @matt.schuh

Account created on 12 September 2016, over 8 years ago
#

Recent comments

πŸ‡ΊπŸ‡ΈUnited States matt.schuh

Is there a way to programmatically do this? I tried following the instructions at the bottom of the page linked in the OP (regarding changing a field type), which appears to grab existing data from the database, remove the old configuration from the db, create and install a new one, then restore the data. However, the instructions reference a column that doesn't seem to exist, so I'm kind of lost on what that is supposed to reference, or what it has changed to if that's the case.

Specifically, at the part where it tries to grab current field data, I'm not entirely sure which data I need to grab. Something like the following code snippet doesn't work:

// $field_storage comes from an array of FieldStorageConfig loaded using \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['type' => 'myfield']);

$field_configs = $entity_type_manager->getStorage('field_config')->loadByProperties(['field_name' => $field_storage->get('field_name')]);


$database = \Drupal::database();
$transaction = $database->startTransaction();
$entity_type_manager = \Drupal::entityTypeManager();

foreach ($field_configs as $field_config) {
  // There's some type checking here just to be safe, but the code from the tutorial that doesn't seem to work is in this part of the snippet.

  $bundle_of = $field_config->get('entity_type');
  $storage = $entity_type_manager->getStorage($bundle_of);

  $table_name = $storage->getDataTable() ?: $storage->getBaseTable();
  $field_name = $field_config->get('field_name');

  // This part throws the error
  $field_values = $database->select($table_name)
    ->fields($table_name, [$id_key, $field_name])
    ->execute()
    ->fetchAllKeyed();
}

 The error I receive is:

Uncaught PHP Exception Drupal\Core\Database\DatabaseExceptionHandler: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node_field_data.field_background_image' in 'field list': SELECT "node_field_data"."nid" AS "nid", "node_field_data"."field_background_image" AS "field_background_image" FROM "node_field_data" "node_field_data"; Array () ...

That error makes sense; the node_field_data table doesn't have that column. What I'm trying to figure out is what table and/or column the tutorial is trying to change.

Production build 0.71.5 2024