Problem/Motivation
During a legacy-to-6.x database upgrade using Simple OAuth 6.1.3 and Drupal 11.4.11, simple_oauth_update_8605() fails with:
Update started: simple_oauth_update_8605 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'scopes_target_id' in 'where clause' Update failed: simple_oauth_update_8605
The update renames oauth2_token__scopes.scopes_target_id to scopes_scope_id before uninstalling the installed legacy entity_reference field definition.
During field uninstallation, Drupal checks whether the field contains data. The installed definition still maps to scopes_target_id, but the physical column has already been renamed, causing the query to fail.
In the observed failed state:
- The installed token
scopesfield type remainedentity_reference. - The table contained
scopes_scope_id, but notscopes_target_id. - The recorded Simple OAuth schema version remained
8604.
Retrying the unchanged update does not repair this mismatch.
Steps to reproduce
- Use a legacy database where update 8605 is pending and the token
scopesfield still uses the installedentity_referencedefinition. - Deploy Simple OAuth 6.1.3.
- Run
drush updatedb. - Observe the missing-column error during update 8605.
This was observed during a local upgrade. Recovery from the resulting partial failure was validated, but reproduction from an untouched legacy database has not yet been independently repeated. Fresh installations using current field definitions are outside the reported scenario.
Proposed resolution
The attached patch removes the premature column rename and lets Drupal uninstall the legacy field using its existing column mapping before installing the replacement field.
It also handles the observed partial failure by restoring scopes_scope_id to scopes_target_id only when:
- The installed
scopesfield exists and usesentity_reference. - The
oauth2_token__scopestable exists. scopes_target_idis absent.scopes_scope_idexists.
The original field uninstall/install logic and token cleanup remain in place. The patch does not manually mark the update complete or implement scope-data migration.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | simple-oauth-8605-restore-legacy-scope-column.patch | 1.96 KB | vtz |
Comments
Comment #2
vtz commentedComment #3
sorlov commentedHave the same issue
but I'm wondering why this block is needed at all:
Looks like patch from #2 solves the mess, made with this block, but not initial issue