Unable to log in to Nextcloud as admin due to failed TOTP update, The column 'last_counter' on table 'oc_twofactor_totp_secrets' already exists

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 12.0.2): 16.0.3.0
Operating system and version (eg, Ubuntu 17.04): Debian 9
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.25
PHP version (eg, 7.1): 7.3.6

The issue you are facing:
When I attempted to log in to Nextcloud as the administrator user, I am prompted to update twofactor_totp. The update fails with the following output:

Set log level to debug
Updating database schema
Updated database
Updating <twofactor_totp> …
Doctrine\DBAL\Schema\SchemaException: The column ‘last_counter’ on table ‘oc_twofactor_totp_secrets’ already exists.
Update failed
Maintenance mode is kept active
Reset log level

If I disable twofacor_totp with occ, the admin user is still unable to login and receives an error that none of my TOTP options are available. I have a backup from when this was working correctly, but if I recover from backups I am presented with the same issue when I attempt to login.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Recover from backup of working instance
  2. Attempt to login
  3. Prompted to update totp, update fails

The output of your Nextcloud log in Admin > Logging:

Unable to login to access interface

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'id',
  'passwordsalt' => 'salt',
  'secret' => 'secret',
  'trusted_domains' =>
  array (
    0 => 'host.domain.org',
  ),
  'datadirectory' => '/var/www/html/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '16.0.3.0',
  'overwrite.cli.url' => 'https://host.domain.org',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'dan',
  'dbpassword' => 'dbpasswd',
  'installed' => true,
  'updater.release.channel' => 'stable',
  'twofactor_enforced' => 'true',
  'login_form_autocomplete' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'twofactor_enforced_groups' =>
  array (
  ),
  'twofactor_enforced_excluded_groups' =>
  array (
    0 => 'New User Setup',
  ),
  'maintenance' => true,
  'theme' => '',
  'loglevel' => 2,
  'mail_from_address' => 'no_reply',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'domain.org',
  'mail_smtpauthtype' => 'LOGIN',
  'upgrade.disable-web' => true,
);


The output of your Apache/nginx/system log in /var/log/____:

PHP Warning:  Module 'exif' already loaded in Unknown on line 0
PHP Warning:  Module 'posix' already loaded in Unknown on line 0
PHP Warning:  Module 'zip' already loaded in Unknown on line 0
PHP Warning:  Module 'mysqlnd' already loaded in Unknown on line 0
PHP Warning:  Module 'apc' already loaded in Unknown on line 0
PHP Warning:  Module 'iconv' already loaded in Unknown on line 0
PHP Warning:  Module 'curl' already loaded in Unknown on line 0
PHP Warning:  Module 'imagick' already loaded in Unknown on line 0
PHP Warning:  Module 'ctype' already loaded in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
PHP Warning:  Module 'mysqli' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_mysql' already loaded in Unknown on line 0
PHP Warning:  Module 'xml' already loaded in Unknown on line 0
PHP Warning:  Module 'sysvmsg' already loaded in Unknown on line 0
PHP Warning:  Module 'gettext' already loaded in Unknown on line 0
PHP Warning:  Module 'sockets' already loaded in Unknown on line 0
PHP Warning:  Module 'xsl' already loaded in Unknown on line 0
PHP Warning:  Module 'gd' already loaded in Unknown on line 0
PHP Warning:  Module 'SimpleXML' already loaded in Unknown on line 0
PHP Warning:  Module 'tokenizer' already loaded in Unknown on line 0
PHP Warning:  Module 'intl' already loaded in Unknown on line 0
PHP Warning:  Module 'mbstring' already loaded in Unknown on line 0
PHP Warning:  Module 'shmop' already loaded in Unknown on line 0
PHP Warning:  Module 'wddx' already loaded in Unknown on line 0
PHP Warning:  Module 'dom' already loaded in Unknown on line 0
PHP Warning:  Module 'xmlwriter' already loaded in Unknown on line 0
PHP Warning:  Module 'readline' already loaded in Unknown on line 0
PHP Warning:  Module 'apcu' already loaded in Unknown on line 0
PHP Warning:  Module 'ftp' already loaded in Unknown on line 0
PHP Warning:  Module 'Phar' already loaded in Unknown on line 0
PHP Warning:  Module 'sysvsem' already loaded in Unknown on line 0
PHP Warning:  Module 'calendar' already loaded in Unknown on line 0
PHP Warning:  Module 'json' already loaded in Unknown on line 0
PHP Warning:  Module 'fileinfo' already loaded in Unknown on line 0
PHP Warning:  Module 'sysvshm' already loaded in Unknown on line 0
PHP Warning:  Module 'xmlreader' already loaded in Unknown on line 0
[Tue Aug 20 10:50:41.000743 2019] [mpm_prefork:notice] [pid 4211] AH00163: Apac$
[Tue Aug 20 10:50:41.000760 2019] [core:notice] [pid 4211] AH00094: Command lin$
Cannot load Zend OPcache - it was already loaded
Cannot load Zend OPcache - it was already loaded
Cannot load Zend OPcache - it was already loaded
Cannot load Zend OPcache - it was already loaded

Any assistance in recovering my Nextcloud instance and ideally preventing this from occurring in the future would be greatly appreciated. Thank you.

Try using the Two-Factor Admin Support app to generate a code from occ.

1 Like

Thank you for the suggestion. Do you know how I can do this from the command line? I have no access to the administrative browser interface.

I created a new user via occ and added them to the admin group. I downloaded Two-factor admin support as suggested and using the new admin user generated a code for my original admin user. I was then able to sign in, but it appears that CSS is no longer working on my site. It seems my problems may be worse than previously recognized, but the most frustrating part is I have backups from a working instance that break immediately after I restore. I’m honestly not sure where to start to fix this now. I guess I will be looking into why CSS isn’t working now and if I can get that fixed then it’s back to working on getting TOTP to update. :frowning:

CSS is working with the theming app disabled, so that is acceptable for now. However I still can’t update TOTP. It returns the following error in the GUI:

The column ‘last_counter’ on table ‘oc_twofactor_totp_secrets’ already exists.

I would greatly appreciate any assistance with this problem with the table. Thank you KarlF12 for the suggestion about Two-Factor Admin Support! That is very good to know about.

That’s getting a little out of my element, but I can tell you I’ve had some issues with the theming myself. Every time I change an image the site gets all screwed up until I restart Apache.

It maybe solved with the following OCC command…

occ migrations:migrate twofactor_totp