Oc_twofactor_providers deleted. How to recover?

Nextcloud version: 14.0.4
Operating system and version: Ubuntu 16.04
Apache or nginx version: apache 2.4
PHP version: 7.2

Hello together,
I accidently deleted the mysql database table “oc_twofactor_providers”. Now users cannot login anymore. What can i do to recreate the table?

Steps to replicate it:

  1. Delete oc_twofactor_providers table from nextcloud database

The output of your Nextcloud log in Admin > Logging:

	Doctrine\DBAL\Exception\TableNotFoundException: An exception occurred while executing 'SELECT `provider_id`, `enabled` FROM `oc_twofactor_providers` WHERE `uid` = ?' with params ["testuser"]: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_twofactor_providers' doesn't exist
/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php - line 128:

Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException("An exceptio ... t", Doctrine\DBA ... ]})

/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php - line 855:

Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Doctrine\DBA ... {}, Doctrine\DBA ... ]}, "SELECT `pro ... ?", { 1: "*** se ... "})

/var/www/nextcloud/lib/private/DB/Connection.php - line 195:

Doctrine\DBAL\Connection->executeQuery("SELECT `pro ... ?", [ "*** sensi ... "], [ 2], "*** sensiti ... *")

/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php - line 206:

OC\DB\Connection->executeQuery("SELECT `pro ... 1", { dcValue1: ... "}, { dcValue1: 2})

/var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php - line 214:

Doctrine\DBAL\Query\QueryBuilder->execute()

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php - line 60:

OC\DB\QueryBuilder\QueryBuilder->execute()

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Registry.php - line 44:

OC\Authentication\TwoFactorAuth\Db\ProviderUserAssignmentDao->getState("*** sensiti ... *")

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Manager.php - line 109:

OC\Authentication\TwoFactorAuth\Registry->getProviderStates(OC\User\User {})

/var/www/nextcloud/core/Controller/LoginController.php - line 334:

OC\Authentication\TwoFactorAuth\Manager->isTwoFactorAuthenticated(OC\User\User {})

/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 166:

OC\Core\Controller\LoginController->tryLogin("*** sensiti ... *")

/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 99:

OC\AppFramework\Http\Dispatcher->executeController(OC\Core\Cont ... {}, "tryLogin")

/var/www/nextcloud/lib/private/AppFramework/App.php - line 118:

OC\AppFramework\Http\Dispatcher->dispatch(OC\Core\Cont ... {}, "tryLogin")

/var/www/nextcloud/lib/private/AppFramework/Routing/RouteActionHandler.php - line 47:

OC\AppFramework\App::main("OC\\Core\\C ... r", "tryLogin", OC\AppFramew ... {}, { _route: "c ... "})


OC\AppFramework\Routing\RouteActionHandler->__invoke({ _route: "c ... "})

/var/www/nextcloud/lib/private/Route/Router.php - line 297:

call_user_func(OC\AppFramew ... {}, { _route: "c ... "})

/var/www/nextcloud/lib/base.php - line 987:

OC\Route\Router->match("/login")

/var/www/nextcloud/index.php - line 42:

OC::handleRequest()

Eingefasst vonDoctrine\DBAL\Driver\PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_twofactor_providers' doesn't exist
/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php - line 847:

Doctrine\DBAL\Driver\PDOStatement->execute()

/var/www/nextcloud/lib/private/DB/Connection.php - line 195:

Doctrine\DBAL\Connection->executeQuery("SELECT `pro ... ?", [ "*** sensi ... "], [ 2], "*** sensiti ... *")

/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php - line 206:

OC\DB\Connection->executeQuery("SELECT `pro ... 1", { dcValue1: ... "}, { dcValue1: 2})

/var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php - line 214:

Doctrine\DBAL\Query\QueryBuilder->execute()

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php - line 60:

OC\DB\QueryBuilder\QueryBuilder->execute()

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Registry.php - line 44:

OC\Authentication\TwoFactorAuth\Db\ProviderUserAssignmentDao->getState("*** sensiti ... *")

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Manager.php - line 109:

OC\Authentication\TwoFactorAuth\Registry->getProviderStates(OC\User\User {})

/var/www/nextcloud/core/Controller/LoginController.php - line 334:

OC\Authentication\TwoFactorAuth\Manager->isTwoFactorAuthenticated(OC\User\User {})

/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 166:

OC\Core\Controller\LoginController->tryLogin("*** sensiti ... *")

/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 99:

OC\AppFramework\Http\Dispatcher->executeController(OC\Core\Cont ... {}, "tryLogin")

/var/www/nextcloud/lib/private/AppFramework/App.php - line 118:

OC\AppFramework\Http\Dispatcher->dispatch(OC\Core\Cont ... {}, "tryLogin")

/var/www/nextcloud/lib/private/AppFramework/Routing/RouteActionHandler.php - line 47:

OC\AppFramework\App::main("OC\\Core\\C ... r", "tryLogin", OC\AppFramew ... {}, { _route: "c ... "})


OC\AppFramework\Routing\RouteActionHandler->__invoke({ _route: "c ... "})

/var/www/nextcloud/lib/private/Route/Router.php - line 297:

call_user_func(OC\AppFramew ... {}, { _route: "c ... "})

/var/www/nextcloud/lib/base.php - line 987:

OC\Route\Router->match("/login")

/var/www/nextcloud/index.php - line 42:

OC::handleRequest()

Eingefasst vonPDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_twofactor_providers' doesn't exist
/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php - line 105:

PDOStatement->execute("*** sensiti ... *")

/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php - line 847:

Doctrine\DBAL\Driver\PDOStatement->execute()

/var/www/nextcloud/lib/private/DB/Connection.php - line 195:

Doctrine\DBAL\Connection->executeQuery("SELECT `pro ... ?", [ "*** sensi ... "], [ 2], "*** sensiti ... *")

/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php - line 206:

OC\DB\Connection->executeQuery("SELECT `pro ... 1", { dcValue1: ... "}, { dcValue1: 2})

/var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php - line 214:

Doctrine\DBAL\Query\QueryBuilder->execute()

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php - line 60:

OC\DB\QueryBuilder\QueryBuilder->execute()

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Registry.php - line 44:

OC\Authentication\TwoFactorAuth\Db\ProviderUserAssignmentDao->getState("*** sensiti ... *")

/var/www/nextcloud/lib/private/Authentication/TwoFactorAuth/Manager.php - line 109:

OC\Authentication\TwoFactorAuth\Registry->getProviderStates(OC\User\User {})

/var/www/nextcloud/core/Controller/LoginController.php - line 334:

OC\Authentication\TwoFactorAuth\Manager->isTwoFactorAuthenticated(OC\User\User {})

/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 166:

OC\Core\Controller\LoginController->tryLogin("*** sensiti ... *")

/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 99:

OC\AppFramework\Http\Dispatcher->executeController(OC\Core\Cont ... {}, "tryLogin")

/var/www/nextcloud/lib/private/AppFramework/App.php - line 118:

OC\AppFramework\Http\Dispatcher->dispatch(OC\Core\Cont ... {}, "tryLogin")

/var/www/nextcloud/lib/private/AppFramework/Routing/RouteActionHandler.php - line 47:

OC\AppFramework\App::main("OC\\Core\\C ... r", "tryLogin", OC\AppFramew ... {}, { _route: "c ... "})


OC\AppFramework\Routing\RouteActionHandler->__invoke({ _route: "c ... "})

/var/www/nextcloud/lib/private/Route/Router.php - line 297:

call_user_func(OC\AppFramew ... {}, { _route: "c ... "})

/var/www/nextcloud/lib/base.php - line 987:

OC\Route\Router->match("/login")

/var/www/nextcloud/index.php - line 42:

OC::handleRequest()

I figured it out myself.

Manually recreated the table like this:

±-------------±---------±--------+
| provider_id | uid | enabled |
±-------------±---------±--------+
| backup_codes | testuser | 0 |
±-------------±---------±--------+

and populated it for each user like this:
INSERT INTO oc_twofactor_providers VALUES (‘backup_codes’,‘testuser’,0);

This topic was automatically closed after 33 hours. New replies are no longer allowed.