Error after Upgrade from 23 to 24.0.2

I had been running NC 23 without any errors and upgraded to 24.0.2. Then I got:

The database is missing some indexes. Due to the fact that adding indexes on big tables could take some time they were not added automatically. By running "occ db:add-missing-indices" those missing indexes could be added manually while the instance keeps running. Once the indexes are added queries to those tables are usually much faster.

So I ran:

sudo -u www-data php occ db:add-missing-indices

That gave me this:

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /var/www/html/nextcloud/lib/private/DB/Connection.php:139
Stack trace:
#0 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\DB\Connection->connect()
#1 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/html/nextcloud/lib/private/DB/Connection.php(261): Doctrine\DBAL\Connection->executeQuery()
#3 /var/www/html/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery()
#4 /var/www/html/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(281): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/html/nextcloud/lib/private/AppConfig.php(411): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/nextcloud/lib/private/AppConfig.php(176): OC\AppConfig->loadConfigValues()
#7 /var/www/html/nextcloud/lib/private/AppConfig.php(367): OC\AppConfig->getApps()
#8 /var/www/html/nextcloud/lib/private/legacy/OC_App.php(983): OC\AppConfig->getValues()
#9 /var/www/html/nextcloud/lib/private/Server.php(713): OC_App::getAppVersions()
#10 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}()
#11 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#12 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#13 /var/www/html/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#14 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#15 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(184): OC\AppFramework\Utility\SimpleContainer->get()
#16 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#17 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#18 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#19 /var/www/html/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#20 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#21 /var/www/html/nextcloud/lib/private/Server.php(1105): OC\AppFramework\Utility\SimpleContainer->get()
#22 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}()
#23 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#24 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#25 /var/www/html/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#26 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#27 /var/www/html/nextcloud/lib/private/Server.php(2082): OC\AppFramework\Utility\SimpleContainer->get()
#28 /var/www/html/nextcloud/lib/private/Files/View.php(122): OC\Server->getLockingProvider()
#29 /var/www/html/nextcloud/lib/private/Server.php(454): OC\Files\View->__construct()
#30 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}()
#31 /var/www/html/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}()
#32 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet()
#33 /var/www/html/nextcloud/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query()
#34 /var/www/html/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query()
#35 /var/www/html/nextcloud/lib/private/Server.php(1445): OC\AppFramework\Utility\SimpleContainer->get()
#36 /var/www/html/nextcloud/lib/base.php(602): OC\Server->boot()
#37 /var/www/html/nextcloud/lib/base.php(1104): OC::init()
#38 /var/www/html/nextcloud/console.php(48): require_once('...')
#39 /var/www/html/nextcloud/occ(11): require_once('...')
#40 {main}

Nextcloud version: 24.0.2
Operating system and version : Ubuntu 20.04
Apache version : 2.4.54
PHP version : 7.4.30

did you run the command from within the NC directory? Is the owner of that directory indeed www-data? Are other PHP versions installed on that machine? Try to run php7.4 instead.

Yes I did run the command from within the NC directory.
Yes the owner is www-data
I do have PHP 8.1 installed as well but it was turned off at the time. I have tried switching to 8.1 and rerunning the commands listed above and got the same errors.

Isn’t Nextcloud still compatible with PHP 8.1?

zoo3 I’m not quite sure what you are asking. According to the NC documentation PHP 8.0 is supported and currently recommended for NC24. PHP 8.1 is not listed however it does work with NC. I’m more lead to believe this more of a database issue than a PHP issue.

I went back through the NC documentation and verified all of the PHP requirements and have all the required PHP modules installed, the correct database connector (pdo_mysql), and some of the recommended PHP modules required for my installation. Still having the error and I’m out of ideas