Unable activate TOTP second-factor auth

Unable to get TOTP second-factor auth functioning. It does show it activated (box is ticked) however the app appears to not have been initialised.

First here’s a description of the activation observations followed by the error log.

  1. Box to activate ticked.
  2. QR code scanned into FreeOTP Android. (App works on a Disroot.org account)
  3. Code generated by FreeOTP
  4. Code entered into TOTP second-factor auth & verify button clicked.
  5. Button and input field is greyed out.
  6. There is no further activity.
  7. Leaving and returning to the security section of Nextcloud 13.0.6 shows TOTP second-factor auth box ticked/activated.
  8. Attempts to login using 2-factor fail
  9. Browser then opens the default Nextcloud page.

Log entry:

Doctrine\DBAL\Exception\InvalidFieldNameException: An exception occurred while executing 'INSERT INTO `oc_activity` (`app`, `subject`, `subjectparams`, `message`, `messageparams`, `file`, `link`, `user`, `affecteduser`, `timestamp`, `priority`, `type`, `object_type`, `object_id`) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["twofactor_totp", "totp_enabled_subject", "[]", "", "[]", "", "", "user7", "user7", 1537615813, 30, "security", "", 0]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'object_type' in 'field list'

    [path]/Nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php - line 128: Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
    [path]/Nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php - line 1015: Doctrine\DBAL\DBALException driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'INSERT INTO `oc...', Array)
    [path]/Nextcloud/lib/private/DB/Connection.php - line 216: Doctrine\DBAL\Connection->executeUpdate('INSERT INTO `oc...', Array, Array)
    [path]/Nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php - line 208: OC\DB\Connection->executeUpdate('INSERT INTO `*P...', Array, Array)
    [path]/Nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php - line 214: Doctrine\DBAL\Query\QueryBuilder->execute()
    [path]/Nextcloud/apps/activity/lib/Data.php - line 100: OC\DB\QueryBuilder\QueryBuilder->execute()
    [path]/Nextcloud/apps/activity/lib/Consumer.php - line 76: OCA\Activity\Data->send(Object(OC\Activity\Event))
    [path]/Nextcloud/lib/private/Activity/Manager.php - line 196: OCA\Activity\Consumer->receive(Object(OC\Activity\Event))
    [path]/Nextcloud/apps/twofactor_totp/lib/Service/Totp.php - line 99: OC\Activity\Manager->publish(Object(OC\Activity\Event))
    [path]/Nextcloud/apps/twofactor_totp/lib/Service/Totp.php - line 109: OCA\TwoFactorTOTP\Service\Totp->publishEvent(Object(OC\User\User), 'totp_enabled')
    [path]/Nextcloud/apps/twofactor_totp/lib/Controller/SettingsController.php - line 99: OCA\TwoFactorTOTP\Service\Totp->enable(Object(OC\User\User), '504637')
    [internal function] OCA\TwoFactorTOTP\Controller\SettingsController->enable(2, '504637')
    [path]/Nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 161: call_user_func_array(Array, Array)
    [path]/Nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 91: OC\AppFramework\Http\Dispatcher->executeController(Object(OCA\TwoFactorTOTP\Controller\SettingsController), 'enable')
    [path]/Nextcloud/lib/private/AppFramework/App.php - line 115: OC\AppFramework\Http\Dispatcher->dispatch(Object(OCA\TwoFactorTOTP\Controller\SettingsController), 'enable')
    [path]/Nextcloud/lib/private/AppFramework/Routing/RouteActionHandler.php - line 47: OC\AppFramework\App main('SettingsControl...', 'enable', Object(OC\AppFramework\DependencyInjection\DIContainer), Array)
    [internal function] OC\AppFramework\Routing\RouteActionHandler->__invoke(Array)
    [path]/Nextcloud/lib/private/Route/Router.php - line 297: call_user_func(Object(OC\AppFramework\Routing\RouteActionHandler), Array)
    [path]/Nextcloud/lib/base.php - line 999: OC\Route\Router->match('/apps/twofactor...')
    [path]/Nextcloud/index.php - line 42: OC handleRequest()
    {main}

Any thoughts on how to proceed?

The error seems to be related to the database of the activity app. I’d try to disable activity app and totp and enable the activity app first and then the totp app, perhaps the missing column is being installed.
If that does not work, we probably should create a bug report for the activity app on github.com/nextcloud/activity/issues

The problem was the activity app.

Disabling both followed by first enabling the activity app then totp still resulted in totp not functioning.

What did work was simply disabling the activity app.

Each time I re-enabled the activity app, totp failed. Deactivate activity app and totp worked again.

Let’s take this as a workaround solution. Please report the bug for the activity app.