Score:0

How to remove a spurious entity update?

id flag

Something (I'm not sure what) has introduced what appears to be a spurious entity update into my Drupal 9 site. I'd like to delete the update so that I'm no longer prompted to apply it.

> drush dentup
user entity type :
The User ID field needs to be updated.

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

In SqlContentEntityStorageSchema.php line 1842:

  The SQL storage cannot change the schema for an existing field (uid in user
   entity) with data.

When I remove all user data and reattempt the update:

> drush dentup
user entity type :
The User ID field needs to be updated.

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

In ExceptionHandler.php line 50:

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY':
  ALTER TABLE "users" ADD `uid` INT unsigned NOT NULL, ADD PRIMARY KEY (`uid`); Array()

In StatementWrapper.php line 116:

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY'

The users table already has a uid column which is its primary key and this entity update will always fail.

Where are entity updates stored? Is there a way to safely remove this update from its storage location?

Score:4
cn flag

This seems very odd, how did the entity schema for the uid field get changed?

So you are saying the user database tables are the same as in any other Drupal install?

What is then with the installed storage schemas, for the tables

\Drupal::keyValue('entity.storage_schema.sql')->get('user.entity_schema_data')

and the field?

\Drupal::keyValue('entity.storage_schema.sql')->get('user.field_schema_data.uid')

If this is the only thing wrong you could set the correct data:

\Drupal::keyValue('entity.storage_schema.sql')->set('user.entity_schema_data', $data)

Drupal keeps track of installed versus in code defined entity definitions. So whatever the unknown code has done, there could be more damage.

id flag
The table value in my dev instance was identical to the corresponding value in the DB for a fresh D9 install. However, there was a difference between the field values. I updated the dev value for `user.field_schema_data.uid` to match the fresh install value and this eliminated the status report error. Thank you, [4k4](https://drupal.stackexchange.com/users/47547/4k4), for your suggestion.
id flag
The questions of how the difference was introduced, and what may lurk in my dev instance, remain. I'll be alert for other errors.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.