Problem/Motivation

We updated from 2.0-alpha4 to 2.0-beta2. The views reference fields are on Commerce product entities. We are now getting a lot of PHP notices in the Drupal error log with information such as the following:
Message Notice: Undefined property: stdClass::$field_display_photos__title in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromDedicatedTables() (line 1288 of /home/shedsandstuff/public_html/lanc/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php)

Steps to reproduce

If a views reference field is on Commerce product entity, and there is existing data in the field, update from 2.0-alpha4 to 2.0-beta2. See the Drupal log.

Proposed resolution

Could be related to https://www.drupal.org/project/viewsreference/issues/2824292. Does the update script need to include product entities?

Remaining tasks

If someone would know how to create a patch or script that would fix the error messages, we would be much obliged.

Comments

Adrian83 created an issue. See original summary.

someshver’s picture

I had a similar issue with field_image
Undefined property: stdClass::$field_image_alt in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromDedicatedTables() (line 1288 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

The Error occurs when there is some column missing in the database table. In your case, the field_display_photos__title column is missing from the tables node_field_display_photos and node_revision_field_display_photos
and in my case the column name is field_image_alt so we need to add column first.

/**
* Adding missing columns field_image alt
*/
function custom_module_update_8003() {

  // Prepare relevant variables.
  $entity_type = 'node';
  $field_name = 'field_image';
  $field_length = 10;

  try {
    // Update database schema.
    $database = \Drupal::database();
    // Add column.
    $database->query("ALTER TABLE {$entity_type}__{$field_name} ADD COLUMN {$field_name}_alt VARCHAR({$field_length}) NOT null DEFAULT 0");
    // Add column to revision.
    $database->query("ALTER TABLE {$entity_type}_revision__{$field_name} ADD COLUMN {$field_name}_alt VARCHAR({$field_length}) NOT null DEFAULT 0");
  } catch (\Exception $e) {
    return $e->getMessage();
  }

  return t('alt column added.');
}

After that run update.php. After all this process you can delete the field and create new field with similar name.

Thanks

someshver’s picture

Status: Active » Needs review
almador’s picture

I'm occurring the same problem in two fields.

When I'm trying to edit fields settings:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_name

Warning code:
Warning: Undefined property: stdClass::$field_name in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromDedicatedTables() (line 1267 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

almador’s picture

And yes, this the fields with '_argument' at the end.

After examining the viewsreference.install code I realized that problem was with the columns with _argument and _title at the end. This is the custom module code I've used to fix the problem:

/**
* Adding missing column 'argument' for field_name
*/
function field_fix_update_8100() {

  // Prepare relevant variables.
  $entity_type = 'node';
  $field_name = 'field_name_';
  $field_length = 10;

  try {
    // Update database schema.
    $database = \Drupal::database();
    // Add column argument.
    $database->query("ALTER TABLE {$entity_type}__{$field_name} ADD COLUMN {$field_name}_argument VARCHAR({$field_length}) NOT null DEFAULT 0");
    // Add column argument to revision.
    $database->query("ALTER TABLE {$entity_type}_revision__{$field_name} ADD COLUMN {$field_name}_argument VARCHAR({$field_length}) NOT null DEFAULT 0");
  } catch (\Exception $e) {
    return $e->getMessage();
  }

  return t('alt column added.');
}

/**
* Adding missing column 'title' for field_name
*/
function field_fix_update_8101() {

  // Prepare relevant variables.
  $entity_type = 'node';
  $field_name = 'field_name_';
  $field_length = 10;

  try {
    // Update database schema.
    $database = \Drupal::database();
	// Add column title.
    $database->query("ALTER TABLE {$entity_type}__{$field_name} ADD COLUMN {$field_name}_title VARCHAR({$field_length}) NOT null DEFAULT 0");
    // Add column title to revision.
    $database->query("ALTER TABLE {$entity_type}_revision__{$field_name} ADD COLUMN {$field_name}_title VARCHAR({$field_length}) NOT null DEFAULT 0");
  } catch (\Exception $e) {
    return $e->getMessage();
  }

  return t('alt column added.');
}

After enabling this module:

drush updb
yes
drush cr
seanb’s picture

seanb’s picture

Status: Needs review » Closed (duplicate)