Hi all,

When updating from 8.4.5 to 8.5.1 I have this error (on 4 different sites):

system-module
#8501 bijwerken
Mislukt: Drupal\Core\Entity\EntityStorageException: The SQL storage cannot change the schema for an existing entity type (node) with data. in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onEntityTypeUpdate() (regel 347 van /home/oms/domains/domain.nl/public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).

What can I do to fix this?

Thanks,
Rolf

Comments

BlinX created an issue. See original summary.

cilefen’s picture

Component: database update system » entity system
Assigned: BlinX » Unassigned
Category: Support request » Bug report
Priority: Critical » Major
mindhunter75’s picture

Same here, i have it on every 8.x website.
subscribing!

rubela_shome’s picture

In the public function onEntityTypeUpdate() there is
requiresEntityStorageSchemaChanges($entity_type, $original) which checks between changed value and the original value.
if return False the requiresEntityDataMigration($entity_type, $original) returns the 'The SQL storage cannot change the schema for an existing entity type (' . $entity_type
->id() . ') with data.' because there a migration needed without recheck what requiresEntityStorageSchemaChanges() has checked.
On search found this function can return FALSE if any of these conditions apply:
1. There are no existing entities for the entity type.
2. There are existing entities, but the schema changes can be applied without losing their data
(e.g., if the schema changes can be performed by altering tables rather than dropping and recreating them).
3. The only entity data that would be lost are ones that are not valid for the new definition
(e.g., if changing an entity type from revisionable to non-revisionable, then it's okay to drop data for the non-default revision).When this function returns FALSE, site administrators will be unable to perform an automated update, and will instead need to perform a site migration or invoke
some custom update process

BlinX’s picture

@rubela_shome, thank you for diving in to this!
Can you tell what you mean by "perform a site migration", if this is a solution to repair this??
Thanks,
Rolf

rubela_shome’s picture

By site migration, I mean to change the version. As you already changed from 8.4.5 to 8.5.1 the suggestion was to revert back/downgrade.
But don't rush to that as it will take you back from where you started. In spite, first of all, you need to pinpoint the cause of the issue.
If I'm not wrong maybe your log files will be able to give you some kind of clue for further investigations and locating the reason.
To locate the involved tables or the issue itself. Might be time consumable but should be helpful. As the function checks that existing data would be lost if the schema changes were applied from the table so if you can find the needed tables
try to update the tables manually, truncate the tables after taking back up of them. Maybe data exists there due to which the function considering
the table can be altered without recreated or deleting.
Also if the entity type is revisionable by deleting the data would cause an issue as revisionable types are valid data and need for a new definition.

g.jordan’s picture

I am also experiencing this issue with going from 8.4.3 to 8.5.0 then to 8.5.1. I was able to deploy the 8.5.0 iteration but I want this fixed in my 8.5.1 deployment. I am experiencing this error on the field entity type "file", rather than "node".

Do you wish to run all pending updates? (yes/no) [yes]:
 > yes

 [error]  Drupal\Core\Entity\EntityStorageException: The SQL storage cannot change the schema for an existing entity type (file) with data. in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onEntityTypeUpdate() (line 347 of /Users/iamtheghost/Sites/devdesktop/ukhealthcare-dev/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php). 
Array	Array
BlinX’s picture

@rubela_shome, Thanks for your detailled info!
I have to dive deep in this...
Am I right when I say this should be caused by a non core module / theme? Since it seems not many people are having this same problem.
I use Adaptive Theme, are there any other user with same problem using AT?

g.jordan’s picture

@BlinX I am using a custom theme and experiencing this issue.

clafferty’s picture

I have two almost identical sites (same theme (custom), content types, blocks, modules, etc.). The only difference between them is the actual content entered and one additional field on the content types (just a text field).

One of the sites upgraded to 8.5.1 with no issue, the other is showing this problem. At first I thought it might be because on the problematic site some of the content types had no content... but adding some then upgrading didn't change anything. I suppose it's possible that something in the content is causing the problem... or that I upgraded the modules/core in a different order between the sites and somehow that caused it. Is there a list somewhere that shows all the updates that 8501 would make? I could edit the database manually, but a little reluctant to do that if I might miss something and break things for future updates.

BlinX’s picture

Do you all also experience that the problem is only there when viewing the website as anonymous user?
When Logged in as Admin or other user it seems to work well!

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

The error on it's own is not a problem, that's how it works. The question is who is calling it and that's not visible from those error messages.

Try adding something like debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) when using drush or enable verbose error logging or set a breakpoint your IDE to see where this is coming from.

What updates are being reported?

Looks like you are using drush 9, so this *might* be coming from a drush entup that it is running? If you check the status page, what kind of entity field mismatches are you seeing there?

Are you using file_entity? which version?

kaurman’s picture

Not relevant as for fixing the bug but should be of interest to everyone facing this problem nevertheless.

See this advisory. There is a patch one can apply if they are unable to update. Considering the seriousness of the vulnerability the update is supposed to deal with, I would recommend giving the patch a shot.

BlinX’s picture

@Berdir, no I do not use Drush, also not file_entity.

Restored older to version;
Applied the patch @kaurman pointed at, by copying files DrupalKernel.php and RequestSanitizer.php (as stated in the patch) to the existing 8.4.5 install;
Thank you @kaurman !
Enabled verbose error logging;
Made BU;
Updated to Drupal 8.5.1 using Installatron;
Ran Update.php :

Drupal database-update

system module
8501 - Add the 'revision_default' field to all relevant entity types.
Change plugin IDs of actions.
Clear caches due to schema changes in core.entity.schema.yml.

views module
Update dependencies for moved bulk field plugin.
Add additional settings to the entity link field and convert node_path usage to entity_link.
Add placeholder settings to string or numeric filters.
Fix cache max age for table displays.
Include views data table provider in views dependencies.

Error:

system-module
#8501 bijwerken
Mislukt: Drupal\Core\Entity\EntityStorageException: The SQL storage cannot change the schema for an existing entity type (node) with data. in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->onEntityTypeUpdate() (regel 347 van /home/oms/domains/domainname.nl/public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php).

In "Recent Log Messages, besides some other error messages, there is a message of type "Cron":

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'revision.revision_default' in 'field list': SELECT revision.vid AS vid, revision.langcode AS langcode, revision.revision_uid AS revision_uid, revision.revision_timestamp AS revision_timestamp, revision.revision_log AS revision_log, revision.revision_default AS revision_default, base.nid AS nid, base.type AS type, base.uuid AS uuid, CASE base.vid WHEN revision.vid THEN 1 ELSE 0 END AS isDefaultRevision FROM {node} base INNER JOIN {node_revision} revision ON revision.vid = base.vid WHERE base.nid IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8, :db_condition_placeholder_9, :db_condition_placeholder_10, :db_condition_placeholder_11, :db_condition_placeholder_12, :db_condition_placeholder_13, :db_condition_placeholder_14, :db_condition_placeholder_15, :db_condition_placeholder_16, :db_condition_placeholder_17, :db_condition_placeholder_18, :db_condition_placeholder_19, :db_condition_placeholder_20, :db_condition_placeholder_21, :db_condition_placeholder_22); Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 4 [:db_condition_placeholder_2] => 3 [:db_condition_placeholder_3] => 6 [:db_condition_placeholder_4] => 7 [:db_condition_placeholder_5] => 10 [:db_condition_placeholder_6] => 12 [:db_condition_placeholder_7] => 13 [:db_condition_placeholder_8] => 15 [:db_condition_placeholder_9] => 16 [:db_condition_placeholder_10] => 19 [:db_condition_placeholder_11] => 20 [:db_condition_placeholder_12] => 21 [:db_condition_placeholder_13] => 22 [:db_condition_placeholder_14] => 5 [:db_condition_placeholder_15] => 2 [:db_condition_placeholder_16] => 8 [:db_condition_placeholder_17] => 14 [:db_condition_placeholder_18] => 18 [:db_condition_placeholder_19] => 11 [:db_condition_placeholder_20] => 9 [:db_condition_placeholder_21] => 17 [:db_condition_placeholder_22] => 23 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->getFromStorage() (regel 455 van /home/oms/domains/domainname.nl/public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Also error with type "Menu":

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'revision.revision_default' in 'field list': SELECT revision.vid AS vid, revision.langcode AS langcode, revision.revision_uid AS revision_uid, revision.revision_timestamp AS revision_timestamp, revision.revision_log AS revision_log, revision.revision_default AS revision_default, base.nid AS nid, base.type AS type, base.uuid AS uuid, CASE base.vid WHEN revision.vid THEN 1 ELSE 0 END AS isDefaultRevision FROM {node} base INNER JOIN {node_revision} revision ON revision.vid = base.vid WHERE base.nid IN (:db_condition_placeholder_0); Array ( [:db_condition_placeholder_0] => 2 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->getFromStorage() (regel 455 van /home/oms/domains/domainname.nl/public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

ALso error with type "PHP":

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'revision.revision_default' in 'field list': SELECT revision.vid AS vid, revision.langcode AS langcode, revision.revision_uid AS revision_uid, revision.revision_timestamp AS revision_timestamp, revision.revision_log AS revision_log, revision.revision_default AS revision_default, base.nid AS nid, base.type AS type, base.uuid AS uuid, CASE base.vid WHEN revision.vid THEN 1 ELSE 0 END AS isDefaultRevision FROM {node} base INNER JOIN {node_revision} revision ON revision.vid = base.vid WHERE base.nid IN (:db_condition_placeholder_0); Array ( [:db_condition_placeholder_0] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->getFromStorage() (regel 455 van /home/oms/domains/domainname.nl/public_html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

@Berdir, are these the logs you are pointing at?
Can you see anything what might be the solution?

Status Report gives this:

ENTITEIT-/VELDDEFINITIES
Niet overeenkomende entiteit en/of velddefinities
De volgende wijzigingen werden gevonden in het entiteitstype en de velddefinities.
Inhoud
Het veld Standaardrevisie moet geïnstalleerd worden.

In English this is something like:

ENTITY / FIELD DEFINITIONS
Non-matching entity and / or field definitions
The following changes were found in the entity type and the field definitions.
Content
The Default revision field must be installed.

BlinX’s picture

Hi all,
My websites seems to be save in version 8.4.7, however upgrading to 8.5.2 still is a problem.
Status report gives (In Dutch):

ENTITEIT-/VELDDEFINITIES
Niet overeenkomende entiteit en/of velddefinities
De volgende wijzigingen werden gevonden in het entiteitstype en de velddefinities.
Inhoud
Het veld Standaardrevisie moet geïnstalleerd worden.

In English this is something like:

ENTITY / FIELD DEFINITIONS
Non-matching entity and / or field definitions
The following changes were found in the entity type and the field definitions.
Content
The Default revision field must be installed.

How to do that??

g.jordan’s picture

How is this still not fixed?

g.jordan’s picture

This is getting old and has now gone into "postponed" status, which is capital-B capital-S. This is breaking lots of sites and yet no one has come up with a solution????

cilefen’s picture

Dear @g.jordan@uky.edu: Comments like your two priors and the one you posted on #2865702-55: Revert schema version when update process failed. are not helpful. I suggest you read https://www.drupal.org/dcoc and think about the thousands of people who have contributed to Drupal over many years so that you can use it, for free. No software is without bugs.

plach’s picture

Well said, @cilefen.

And to reply to #16 - #17, the reason why this is not fixed yet and that the postponed (needs more info) status is Appropriate (capital A), is that no one has been able to provide instructions to reproduce the issue yet, which makes working on a fix basically impossible.

If you are so eager to see this fixed, one thing that could help would be to upload an anonymized version of your DBs and Drupal source code (data files are not needed), so that they can be run locally and hopefully the issue can be reproduced.

kaurman’s picture

Had a look at this & tried to update via Drush. The obvious & known part is that it all revolves around revision_default but I have some further questions about the matter.

Here's a fully translated version of what Drush says in response to updb:

[notice] Update started: system_update_8501
[error] An existing "Default revision" field was found for the Custom block entity type, but no "revision_default" revision metadata key was found in its definition.
[error] The SQL storage cannot change the schema for an existing entity type (node) with data.
[error] Update failed: system_update_8501
[error] Update aborted by: system_update_8501
[error] Finished performing updates.

I had some custom blocks indeed (Text (formatted, long, with summary), if I'm not mistaken) that contained rather simple html. Removed them (i.e custom blocks library appears to be empty at the moment), cleared the cache and tried again but received the same error message. Why is the system still blabbing about custom blocks?

List of entities, just in case anyone's interested:

 [0] => block
    [1] => block_content_type
    [2] => block_content
    [3] => comment_type
    [4] => comment
    [5] => contact_form
    [6] => contact_message
    [7] => editor
    [8] => field_config
    [9] => field_storage_config
    [10] => file
    [11] => filter_format
    [12] => image_style
    [13] => language_content_settings
    [14] => configurable_language
    [15] => node_type
    [16] => node
    [17] => rdf_mapping
    [18] => search_page
    [19] => shortcut
    [20] => shortcut_set
    [21] => action
    [22] => menu
    [23] => taxonomy_vocabulary
    [24] => taxonomy_term
    [25] => tour
    [26] => user
    [27] => user_role
    [28] => menu_link_content
    [29] => view
    [30] => base_field_override
    [31] => date_format
    [32] => entity_view_mode
    [33] => entity_view_display
    [34] => entity_form_display
    [35] => entity_form_mode

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

punamshelke’s picture

Hi,

I am also facing the same issue...
can you suggest me the way to resolve this issue

damondt’s picture

This error would be thrown during an update if changes to an entity type definition were being attempted in an update hook and the db columns implied by the entity type definition did not match the actual columns. The described set of circumstances would cause ContentEntityStorageSchema->hasColumnChanges() to return true meaning that the change could not be made with content of that entity type. When I encountered this issue it was due to a module called multiversion that did not clean up after it's self when uninstalled.

MarianT’s picture

Issue tags: +Seattle2019
MarianT’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Issue tags: -Seattle2019

This has been fixed in 8.7

BlinX’s picture

MarianT are you sure this is fixed? I tried again and no succes!
Why did you close this issue without mentioning where the duplicate is??
Can someone with more knowledge please look after this?

mrweiner’s picture

Status: Closed (duplicate) » Active

Shouldn't close as a duplicate without stating where the duplicate is.

amateescu’s picture

Status: Active » Closed (duplicate)
BlinX’s picture

@amateescu, I tried again updating from Drupal 8.4.8 to 8.7.3 but without succes!
I use Installatron to update to new versions.
In Installatron, this message appeared:
Upgrading: Error: 2019-07-07 16:11:44.58008000 FAILURE [3; /usr/bin/curl] https://(domain).nl/update.php/start?id=65&op=do_nojs&op=do&_format=json&continue=1 [http code=500]

What should I do? Can you help me?
Thanks in advance!

damondt’s picture

I would argue that the referenced issue is not an exact duplicate as the revisionable status of an entity type definition changing is not the only reason that schema changes could be required. That being said, I don't know that a generic solution is possible.

mrunwal’s picture

I have upgraded Drupal 8.8 to 9.5.2
php 8.1

I am still facing same issue. is there alternate way to fix it either manually by checking db tables to fix it ?

qsurti’s picture

I have recently installed Drupal 10 on my website, and I am also receiving similar errors as follows;
>>
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Media type
The Media type entity type needs to be installed.
Media
The Media entity type needs to be installed.
>>

mariskath’s picture

I'm having the same problem. I work on Drupal 10.1.2
On my status report it says:
"Entity/field definitions
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
Media
The Media entity type needs to be installed.
Media type
The Media type entity type needs to be installed."

The media module is part of core and enabled.

When I go to 'uninstall', I get the following errors. Striking is that ' media' is mentioned again, so I think it is related:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table '4tuethics.media' doesn't exist: SELECT "base_table"."vid" AS "vid", "base_table"."mid" AS "mid" FROM "media" "base_table" GROUP BY "base_table"."vid", "base_table"."mid" LIMIT 1 OFFSET 0; Array ( ) in Drupal\Core\Entity\Query\Sql\Query->result() (line 271 of core\lib\Drupal\Core\Entity\Query\Sql\Query.php).

Drupal\Core\Database\StatementWrapperIterator->execute(Array, Array) (Line: 790)
Drupal\Core\Database\Connection->query('SELECT "base_table"."vid" AS "vid", "base_table"."mid" AS "mid"
FROM
{media} "base_table"
GROUP BY "base_table"."vid", "base_table"."mid"
LIMIT 1 OFFSET 0', Array, Array) (Line: 525)
Drupal\Core\Database\Query\Select->execute() (Line: 271)
Drupal\Core\Entity\Query\Sql\Query->result() (Line: 84)
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 617)
Drupal\Core\Entity\EntityStorageBase->hasData() (Line: 43)
Drupal\Core\Entity\ContentUninstallValidator->validate('media') (Line: 624)
Drupal\Core\Extension\ModuleInstaller->validateUninstall(Array) (Line: 99)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->validateUninstall(Array) (Line: 161)
Drupal\system\Form\ModulesUninstallForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('system_modules_uninstall', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Best regards,
Mariska

mariskath’s picture

I have run into this problem multiple times now.

The patch in #57 of this thread works for me. https://www.drupal.org/project/drupal/issues/2563515

Best regards,
Mariska