Update to 20.0.4 failed

Nextcloud version: (19.0.6)
Operating system and version: (Ubuntu 18.04)
Apache version: (Apache 2.4.29)
PHP version: (7.3)

Hi, when trying to do a routine upgrade from 19.0.6 -> 20.0.4 the upgrade failed with the following error:
Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'ALTER TABLE oc_authtoken CHANGE password_invalid password_invalid TINYINT(1) DEFAULT '0'': SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Detailed log:

Preparing update

Set log level to debug

Turned on maintenance mode

Repair step: Repair MySQL collation

Repair info: All tables already have the correct collation -> nothing to do

Repair step: Repair SQLite autoincrement

Repair step: Copy data from accounts table when migrating from ownCloud

Repair step: Drop account terms table when migrating from ownCloud

Updating database schema

Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'ALTER TABLE oc_authtoken CHANGE `password_invalid` password_invalid TINYINT(1) DEFAULT '0'': SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

The update was unsuccessful. Please report this issue to the Nextcloud community.

The output of your config.php file in /path/to/nextcloud:

<?php
$CONFIG = array (
  'instanceid' => 
  'passwordsalt' => ,
  'secret' => ,
  'trusted_domains' =>
  'datadirectory' => 
  'dbtype' => 'mysql',
  'version' => '19.0.6.2',
  'overwrite.cli.url' => 
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'nextcloud',
  'installed' => true,
  'activity_expire_days' => 14,
  'auth.bruteforce.protection.enabled' => true,
  'blacklisted_files' =>
  array (
    0 => '.htaccess',
    1 => 'Thumbs.db',
    2 => 'thumbs.db',
  ),
  'cron_log' => true,
  'enable_previews' => true,
  'enabledPreviewProviders' =>
  array (
    0 => 'OC\\Preview\\PNG',
    1 => 'OC\\Preview\\JPEG',
    2 => 'OC\\Preview\\GIF',
    3 => 'OC\\Preview\\BMP',
    4 => 'OC\\Preview\\XBitmap',
    5 => 'OC\\Preview\\Movie',
    6 => 'OC\\Preview\\PDF',
    7 => 'OC\\Preview\\MP3',
    8 => 'OC\\Preview\\TXT',
    9 => 'OC\\Preview\\MarkDown',
  ),
  'filesystem_check_changes' => 0,
  'filelocking.enabled' => 'true',
  'htaccess.RewriteBase' => '/',
  'integrity.check.disabled' => false,
  'knowledgebaseenabled' => false,
  'logfile' => '/var/nc_data/nextcloud.log',
  'loglevel' => 2,
  'logtimezone' =>
  'log_rotate_size' => 104857600,
  'maintenance' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'overwriteprotocol' => 'https',
  'preview_max_x' => 1024,
  'preview_max_y' => 768,
  'preview_max_scale_factor' => 1,
  'redis' =>
  'quota_include_external_storage' => false,
  'share_folder' => '/Shares',
  'skeletondirectory' => '',
  'theme' => '',
  'trashbin_retention_obligation' => 'auto, 7',
  'updater.release.channel' => 'stable',
  'updater.secret' => 
);

it’s mostly is a real surprise what a simple search on the forum would find as possible solutions…
like

so pls search the forum before posting a “new” issue.

awww… and please let us know if this was doing the trick for you or not.

Hi, thanks for pointing out. I tried the solutions in that thread, and get the following error:

Nextcloud or one of the apps require upgrade - only a limited number of commands are available You may use your browser or the occ upgrade command to do the upgrade

Running that sequence of commands doesn’t seem to solve my issue.

Edit: This appears to be more my issue: https://github.com/nextcloud/server/issues/24326

The commands seem risky, I’ll try tomorrow and report back.

Upon some further digging, it seems that this issue is different from the one in that thread and the bug report. Both those things deal with the following issue primarily:
https://stackoverflow.com/questions/3170634/how-to-solve-cannot-add-a-not-null-column-with-default-value-null-in-sqlite3
Which gives this error from the bug report:
ALTER TABLE oc_activity_mq ADD COLUMN amq_subjectparams CLOB NOT NULL

However, the issue I have I think is the following:
https://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes
And my error is as stated above.

Additionally, the issue I have is with a different table than described in those posts. The solution proposed there is to drop the oc_activity_mq table and recreate it. My issue is in the oc_authtoken table, which I cannot very well drop.

After more searching, this particular issue was the one I was facing: https://github.com/nextcloud/server/issues/24222

However, somehow the solution there did not help me. I was however able to manually change parameters instead of config file using the following commands following the guidance in that post:

SET GLOBAL innodb_large_prefix = ON;
SET GLOBAL innodb_file_format = Barracuda;
SET GLOBAL innodb_file_per_table = ON;

Running occ upgrade after that worked!

I hope you don’t mind me adding to your thread.
I found your thread helpful but in my case lacking and I needed to do a bit more to fix my setup when it got stuck updating to 20.0.6

For those that find this post and don’t know the commands to get into mysql and make the changes listed above and you received the following error from the command line…

Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'ALTER TABLE oc_authtoken CHANGE `password_invalid` password_invalid TINYINT(1) DEFAULT '0'':

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
Update failed

I used this website to figure it out…
Login to MySQL

You’ll need to get to the command line of your installation if you haven’t already.

You’ll need to use your root account for your MySQL…

mysql -u root -p
Enter your root password which you should have noted somewhere

Enter the above commands…

SET GLOBAL innodb_large_prefix = ON;
SET GLOBAL innodb_file_format = Barracuda;
SET GLOBAL innodb_file_per_table = ON;

Exit with the command “exit”

Then locate occ

locate occ

cd to that directory, in my case it is /usr/local/www/apache24/data/nextcloud

then run the following commands…
(Note: Replace www with your user. My user is www, if you don’t remember your user then ls -l to see who owns the files in the current folder)

sudo -u www php occ maintenance:repair
sudo -u www php occ app:update --all
sudo -u www php occ app:disable activity
sudo -u www php occ upgrade
sudo -u www php occ maintenance:mode --off

This is what fixed it for me