Constraint violation during upgrade (oc_oauth2_access_tokens.hashed_code)

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 30.0.4 / 30.0.2
  • Operating system and version (e.g., Ubuntu 24.04):
    • Fedora 41
  • Web server and version (e.g, Apache 2.4.25):
    • Apache 2.4.62
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • nope
  • PHP version (e.g, 8.3):
    • 8.3.15
  • Is this the first time you’ve seen this error? (Yes / No):
    • No`
  • When did this problem seem to first start?
    • Nextcloud 30.0.2
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Update through the Updater in the Admin Panel
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • No

Summary of the issue you are facing:

I am trying to upgrade from 30.0.1 to either 30.0.2 or 30.0.4.
I am doing this through the admin panel (Open Updater).

The first step (checks, backup, download, extract) works fine.
But the second step, the database upgrade / repair fails at a certain point.

Steps to replicate it (hint: details matter!):

  1. Open Updater
  2. Update to the latest version

Log entries

Preparing update
Set log level to debug
Turned on maintenance mode
Repair step: Repair MySQL collation
Repair info: Not a mysql database → nothing to do
Repair step: Copy data from accounts table when migrating from ownCloud
Repair step: Drop account terms table when migrating from ownCloud
Updating database schema
Updated database
Repair step: Upgrading Circles App
Updated “circles” to 30.0.0
Repair step: AppAPI Daemons configuration GPU params update
Repair info: Daemons configuration GPU params updated: 0
Updated “app_api” to 4.0.3
Repair step: Repair MySQL collation
Repair info: Not a mysql database → nothing to do
Repair step: Clean tags and favorites
Repair info: 0 tags of deleted users have been removed.
Repair info: 0 tags for delete files have been removed.
Repair info: 0 tag entries for deleted tags have been removed.
Repair info: 0 tags with no entries have been removed.
Repair step: Repair invalid shares
Repair step: Move .step file of updater to backup location
Repair info: .step file exists
Repair info: .step-previous-update removed
Repair info: .step file moved to .step-previous-update
Repair step: Add move avatar background job
Repair info: Repair step already executed
Repair step: Add preview cleanup background jobs
Repair step: Migrate oauth2_clients table to nextcloud schema
Repair info: Update the oauth2_access_tokens table schema.
Repair info: Update the oauth2_clients table schema.
Repair error: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: oc_oauth2_access_tokens.hashed_code

Any idea how I can fix this constraint violation ???

Regards,
Oliver

Are you using oauth2? Did you migrate from owncloud originally?

I am trying to upgrade from 30.0.1 to either 30.0.2 or 30.0.4.

Has this instance been updated ever before? I wouldn’t expect this code to triggered anew.

Hi jtr

Thanks for the fast response.

Yes, I upgraded or should I say sidegraded from Owncloud around two years ago. Can’t remember but there was a release combination owncloud/nextcloud where this was officially supported. And it worked.

Since then I went through a lot of Nextcloud releases. Can’t remember.

27/28/29 and then to 30.0.1

Then the problem appeared when upgrading to 30.0.2

If I use OAuth2 for login? Hard to say. Could be. When I login with username and password I didn’t have to reenter the credentials for a long time. Could be that there is a token.

Could I just disable the OAuth2 stuff or would that break my login behaviour ? Could I lock myself out ?

And would disabling/removing OAuth2 fix the constraint violation problem?

Regards,
Oliver

There indeed is an OAuth2 client definition under Security:

Name : ownCloud Web
Redirection URI : https://www.mydomain.com/apps/owncloud/index.php/apps/web/oidc-callback.html

BTW, the URI is still wrong as it includes owncloud instead of nextcloud.
So I assume it isn’t working anyway.

Regards,
Oliver

Any idea how to fix this ?

Regards,
Oliver

I’m not sure offhand. I did run across this this morning though, and it is in that area of code and specific to ownCloud migrations: [Bug]: The schema of `oc_oauth2_access_tokens` is not adjusted properly and its data is not migrated correctly when migrating from ownCloud · Issue #50186 · nextcloud/server · GitHub

Thanks for opening an issue request about that.

Regards,
Oliver

Hi jtr

Seems the issue is fixed in version 30.0.5. Update went smooth.
And during the upgrade sequence there was a step kicking out those OC related redirect URIs/Tokens.

Thanks for helping
Regards
Oliver