- Issue created by @Ahmed.Raza
- π΅π°Pakistan Ahmed.Raza
Have you searched drupal.org for that message?
Yes @cilefen, found some similar issues but those related to contrib modules that I am not even using.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
The achema_diff module will help diagnose this
- πΊπΈUnited States joakland
The schema_diff module isn't compatible with D10, which is the version listed in ahmed.raza's description of the problem. For the record, I am having the same issue, also on 10.1.6.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
I can make a d10 release, one moment
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
There you go https://www.drupal.org/project/schema_diff/releases/1.0.0-alpha2 β ποΈ
- π΅π°Pakistan Ahmed.Raza
Thanks @larowlan, I think we've met somewhere before on some issue.. xD
Anyways, I've installed the module and here is the diff in detail. It's the column type only which is previously `int` and now wants to be `serial`. So exactly do I fix this?
A little bit of history, the site was originally built in Drupal 8, a few months back it was updated to Drupal 9.something and now its updated to Drupal 10.1.6 and facing getting this error ever since.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
It sounds like update.php wasn't run on Drupal 9.5 before you moved to D10
This update didn't run https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/modules/user...
- πΊπΈUnited States joakland
The site I'm working on has a similar history; started on D8, was updated to 9 and now 10. I can confirm that we ran update.php before moving to D10, but somehow that schema change got skipped. However, thanks to the function that larowan pointed to in the repo, I was able to resolve this issue. I took the core update 9301 function and tweaked it a bit to run in a custom module:
function _user_update_9301() { // if (!\Drupal::entityTypeManager()->getStorage('user') instanceof SqlContentEntityStorage) { // print_r(t('The user entity storage is not using an SQL storage, update skipped.')); // } $connection = \Drupal::database(); // if ($connection->databaseType() === 'sqlsrv') { // print_r(t('The Microsoft SQL Server does not support user_update_9301() because it causes data loss.')); // } if ($connection->databaseType() === 'mysql') { $sql_mode = $connection->query("SELECT @@sql_mode;")->fetchField(); $connection->query("SET sql_mode = '$sql_mode,NO_AUTO_VALUE_ON_ZERO'"); $new_keys = []; } else { $new_keys = ['primary key' => ['uid']]; $connection->schema()->dropPrimaryKey('users'); } $connection->schema()->changeField('users', 'uid', 'uid', ['type' => 'serial', 'not null' => TRUE], $new_keys); if (isset($sql_mode)) { $connection->query("SET sql_mode = '$sql_mode'"); } // Update the last installed schema to reflect the change of field type. $installed_storage_schema = \Drupal::keyValue('entity.storage_schema.sql'); $field_schema_data = $installed_storage_schema->get('user.field_schema_data.uid'); $field_schema_data['users']['fields']['uid']['type'] = 'serial'; $installed_storage_schema->set('user.field_schema_data.uid', $field_schema_data); // The new PostgreSQL sequence for the uid field needs to start with the last // used user ID + 1 and the sequence must be owned by uid field. // @todo https://drupal.org/i/3028706 implement a generic fix. if ($connection->driver() == 'pgsql') { $maximum_uid = $connection->query('SELECT MAX([uid]) FROM {users}')->fetchField(); $seq = $connection->makeSequenceName('users', 'uid'); $connection->query("ALTER SEQUENCE " . $seq . " RESTART WITH " . ($maximum_uid + 1) . " OWNED BY {users}.uid"); } }
I then added it to the .module file of a custom module and ran it using drush:
drush php-eval '_user_update_9301();'
The error is no longer appearing on the status page.
- π΅π°Pakistan Ahmed.Raza
@joakland I followed your solution and when running `drush php-eval '_user_update_9301();'` it says;
Error: Call to undefined function _user_update_9301() in eval() (line 1 of /Users/ahmedraza/sites/mysite/vendor/drush/drush/src/Commands/core/PhpCommands.php(30) : eval()'d code) #0 /Users/ahmedraza/sites/mysite/vendor/drush/drush/src/Commands/core/PhpCommands.php(30): eval()
- πΊπΈUnited States joakland
@ahmed.raza At risk of insulting your intelligence (for which I apologize in advance), make sure that your custom module is activated, that you've cleared the Drupal cache, and that the function is in the
.module
file. Drupal is picky about where it looks for functions. For example, I tried putting this in my custom theme's.theme
file and I got the same error you listed above. - π΅π°Pakistan Ahmed.Raza
@joakland, the module was already enable as it is a common tweaks module serving tweak purpose on various of site hence its already enabled, no offense taken :D
The mistake was I placed this function in the .install file and not in .module file. So I moved it in .module file and ran the drush command to call this function and it worked the error is now gone. Thanks for your help!
- Status changed to Closed: works as designed
about 1 year ago 7:40am 8 December 2023 I have the same problem but in different Entity.
After upgrade core drupal to drupal 10.0.6 i have this in my report/statusEntity/field definitions Mismatched entity and/or field definitions The following changes were detected in the entity type and field definitions. scheduled transition The Entity field needs to be updated.
- πΊπΈUnited States mmrtnt
#12 π¬ The User ID field needs to be updated. Closed: works as designed Worked for me.
Same circumstances - upgrade from 8.9 to 9.5 to 10.2.
Thanks Joakland β
- πΊπΈUnited States jeffersonpatron
#12 π¬ The User ID field needs to be updated. Closed: works as designed Works great for me. This Drupal was upgraded from 8.9 to 9.5 and now 10.2 Thank you guys
- πΊπΈUnited States bwoods
#12 worked for me as well. I assume the site I patched had a similar history with the upgrades since I recently took them over. Thank you!