I upgraded the site using Composer. I checked for new versions for all modules listed as required in composer.json and updated as needed. I ran update.php. The status page shows that Drupal 8.2.1 is installed, however, it contains this error:

Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
File

The Language code field needs to be updated.

When I view the front page, I get a WSOD with this error:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'revision.langcode' in 'field list': SELECT revision.revision_id AS revision_id, revision.langcode AS langcode, revision._deleted AS _deleted, revision._rev AS _rev, base.fid AS fid, base.uuid AS uuid, base.uid AS uid, base.filename AS filename, base.uri AS uri, base.filemime AS filemime, base.filesize AS filesize, base.status AS status, base.created AS created, base.changed AS changed, base.workspace AS workspace, CASE base.revision_id WHEN revision.revision_id THEN 1 ELSE 0 END AS isDefaultRevision FROM {file_managed} base INNER JOIN {file_revision} revision ON revision.revision_id = base.revision_id WHERE (base.fid IN (:db_condition_placeholder_0)) AND (revision._deleted = :db_condition_placeholder_1) AND (base.workspace = :db_condition_placeholder_2); Array ( [:db_condition_placeholder_0] => 111 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->getFromStorage() (line 428 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

In short, a select is being performed on the field_revision table, and it is failing because the 'langcode' column is missing. This is making the site unusable.

I read that sometimes "drush entity-updates" can resolve the "Mismatched entity and/or field definitions." I tried that, and it just threw the same error:

$ drush entity-updates
The following updates are pending:

file entity type :
The Language code field needs to be updated.
Do you wish to run all pending updates? (y/n): y
Drupal\Core\Entity\EntityStorageException: Exception thrown while performing a schema update. SQLSTATE[42S22]: [error]
Column not found: 1054 Unknown column 't.langcode' in 'field list': SELECT t.langcode AS langcode
FROM
{file_revision} t
WHERE (t.langcode IS NULL )
LIMIT 1 OFFSET 0; Array
(
)
in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() (line 1474 of
[/path/to/]core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Failed: Drupal\Core\Entity\EntityStorageException: !message in [error]
Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() (line 1474 of
[/path/to/]core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Cache rebuild complete. [ok]
Finished performing updates. [ok]

That is where I am now with this. I am not sure how to proceed. I am not even sure what update, if any, should have altered the file_revision table to add the langcode column. If anybody can help point me in the right direction, I would appreciate it.

Comments

John Lawter’s picture

Interesting. "drush entity-updates" was throwing an error yesterday. I gave that another shot today and the updates were applied without error. I looked at the status page to confirm, and sure enough, the "Mismatched entity and/or field definitions" message regarding the langcode field went away and the site appears to be working normally. Go figure.

nicholas.alipaz’s picture

Interesting that the error just resolved itself. I too have the same error after update from D8.1 to D8.2 and I can't run the entity-updates successfully nor cron.

nicholas.alipaz’s picture

So, in attempts of fixing this I added the missing column to file_revision table, however that did fix an issue I was seeing when attempting to delete some nodes. But the drush entity-updates is still failing

check the
manual that corresponds to your MariaDB server version for the right
syntax to use near 'NOT NULL' at line 1: ALTER TABLE {file_revision}
CHANGE `langcode` `langcode`  NOT NULL; Array
(
)
nicholas.alipaz’s picture

Just a quick follow-up to say that this issue has not simply gone away for me after a few days of waiting and seeing.

norwegian.blue’s picture

"drush entity-updates" resolved the issue for me after "drush updb" (drupal 8.2.8)

allabakash.g’s picture

Thanks, drush entup worked for me.

drush entup

sprite’s picture

Just following.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

Mojiferous’s picture

I'm having this same issue, and stepping through the EntityDefinitionUpdateManager::applyUpdates() call that causes the exception, I have a little more insight, but no solution:

It seems like the update manager's comparison of the installed schema for the file entity is picking up the file_revision table and attempting to update the langcode field to have a NOT NULL constraint. The db update function tries to do this as ALTER TABLE {file_revision} CHANGE `langcode` `langcode` NOT NULL, but it is missing the the column definition -- changing this in MySQL as ALTER TABLE file_revision CHANGE `langcode` `langcode` varchar(12) NOT NULL does not throw an error, but without knowing how the update manager gets field storage definitions and why it's not getting the column type for file_revision I'm at a loss at how to fix this.

bmateus’s picture

Any new insight on this issue?

Bruno Mateus

allabakash.g’s picture

Take the database backup
and execute entity-updates command, if it shows error, execute again, it will update by itself.

drush entup

DhirendraGrazitti’s picture

I have run drush entup but error is coming and not resolved . I am using drupal 8.37

The following updates are pending:

 block_content entity type :
  The Revision create time field needs to be updated.
  The Revision user field needs to be updated.
Do you wish to run all pending updates? (y/n): y
Drupal\Core\Entity\EntityStorageException: Exception thrown while performing a schema update. SQLSTATE[42S22]: Column not found: 1054 Unknown column         [error]
'revision_created' in 'where clause': SELECT 1 AS expression
FROM
{block_content_field_data} t
WHERE revision_created IS NOT NULL
LIMIT 1 OFFSET 0; Array
(
)
 in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() (line 1485 of
/path/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Failed: Drupal\Core\Entity\EntityStorageException: !message in Drupal\Core\Entity\Sql\SqlContentEntityStorage->wrapSchemaException() (line 1485 of        [error]
/path/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Cache rebuild complete.                                                                                                                                      [ok]
Finished performing updates. 

I would appreciate it if anybody can help me.

uddhi108’s picture

I uninstalled the block module and all the ones that depended on it. I've reinstalled them and the error message is now gone...

adamschan’s picture

I have applied the patches in 2865702 and this problem is fixed too.