Opening txt- and md files: Failed to load file / OC\DB\Exceptions\DbalException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'oc_text_sessions.PRIMARY'

Nextcloud version: 26.0.1
Operating system and version_: Linux
Apache or nginx version: don’t know
PHP version: 8.2

The issue you are facing:

Is this the first time you’ve seen this error?: No. I think its after updating from NC 20 … NC26 or after updating database to MySQL 8 or after installing and removing NC Office + Collabora Server.

Steps to replicate it:

  1. Open a txt- or md file.

The output of your Nextcloud log in Admin > Logging:

[index] Fehler: OC\DB\Exceptions\DbalException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'oc_text_sessions.PRIMARY' at <<closure>>

 0. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 328
    OC\DB\Exceptions\DbalException::wrap(["Doctrine\\DBAL ... "])
 1. /var/www/vhosts/*****/html/main/nextcloud/lib/public/AppFramework/Db/QBMapper.php line 138
    OC\DB\QueryBuilder\QueryBuilder->executeStatement()
 2. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/SessionService.php line 100
    OCP\AppFramework\Db\QBMapper->insert(["OCA\\Text\\Db\ ... "])
 3. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/ApiService.php line 129
    OCA\Text\Service\SessionService->initSession("*** sensitive parameters replaced ***", "*** sensitive parameters replaced ***")
 4. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Controller/SessionController.php line 61
    OCA\Text\Service\ApiService->create("*** sensitive parameters replaced ***")
 5. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 230
    OCA\Text\Controller\SessionController->create("*** sensitive parameters replaced ***")
 6. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 137
    OC\AppFramework\Http\Dispatcher->executeController(["OCA\\Text\\Con ... "], "create")
 7. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/App.php line 183
    OC\AppFramework\Http\Dispatcher->dispatch(["OCA\\Text\\Con ... "], "create")
 8. /var/www/vhosts/*****/html/main/nextcloud/lib/private/Route/Router.php line 315
    OC\AppFramework\App::main("OCA\\Text\\Cont ... r", "create", ["OC\\AppFramewo ... "], ["text.Session.create"])
 9. /var/www/vhosts/*****/html/main/nextcloud/lib/base.php line 1056
    OC\Route\Router->match("/apps/text/session/create")
10. /var/www/vhosts/*****/html/main/nextcloud/index.php line 36
    OC::handleRequest()

Caused by:

Doctrine\DBAL\Exception\UniqueConstraintViolationException: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'oc_text_sessions.PRIMARY' at <<closure>>

 0. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1814
    Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter->convert(["Doctrine\\DBAL ... "], ["Doctrine\\DBAL\\Query"])
 1. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1749
    Doctrine\DBAL\Connection->handleDriverException(["Doctrine\\DBAL ... "], ["Doctrine\\DBAL\\Query"])
 2. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1163
    Doctrine\DBAL\Connection->convertExceptionDuringQuery(["Doctrine\\DBAL ... "], "INSERT INTO `oc ... )", ["*** sensitive  ... 2], [1,2,2,2,1])
 3. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/Connection.php line 297
    Doctrine\DBAL\Connection->executeStatement("INSERT INTO `oc ... )", ["*** sensitive  ... 2], [1,2,2,2,1])
 4. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php line 354
    OC\DB\Connection->executeStatement("INSERT INTO `oc ... )", ["*** sensitive  ... 2], [1,2,2,2,1])
 5. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 280
    Doctrine\DBAL\Query\QueryBuilder->execute()
 6. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 326
    OC\DB\QueryBuilder\QueryBuilder->execute()
 7. /var/www/vhosts/*****/html/main/nextcloud/lib/public/AppFramework/Db/QBMapper.php line 138
    OC\DB\QueryBuilder\QueryBuilder->executeStatement()
 8. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/SessionService.php line 100
    OCP\AppFramework\Db\QBMapper->insert(["OCA\\Text\\Db\ ... "])
 9. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/ApiService.php line 129
    OCA\Text\Service\SessionService->initSession("*** sensitive parameters replaced ***", "*** sensitive parameters replaced ***")
10. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Controller/SessionController.php line 61
    OCA\Text\Service\ApiService->create("*** sensitive parameters replaced ***")
11. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 230
    OCA\Text\Controller\SessionController->create("*** sensitive parameters replaced ***")
12. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 137
    OC\AppFramework\Http\Dispatcher->executeController(["OCA\\Text\\Con ... "], "create")
13. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/App.php line 183
    OC\AppFramework\Http\Dispatcher->dispatch(["OCA\\Text\\Con ... "], "create")
14. /var/www/vhosts/*****/html/main/nextcloud/lib/private/Route/Router.php line 315
    OC\AppFramework\App::main("OCA\\Text\\Cont ... r", "create", ["OC\\AppFramewo ... "], ["text.Session.create"])
15. /var/www/vhosts/*****/html/main/nextcloud/lib/base.php line 1056
    OC\Route\Router->match("/apps/text/session/create")
16. /var/www/vhosts/*****/html/main/nextcloud/index.php line 36
    OC::handleRequest()

Caused by:

Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'oc_text_sessions.PRIMARY' at <<closure>>

 0. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php line 103
    Doctrine\DBAL\Driver\PDO\Exception::new(["PDOException", ... ]])
 1. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1153
    Doctrine\DBAL\Driver\PDO\Statement->execute()
 2. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/Connection.php line 297
    Doctrine\DBAL\Connection->executeStatement("INSERT INTO `oc ... )", ["*** sensitive  ... 2], [1,2,2,2,1])
 3. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php line 354
    OC\DB\Connection->executeStatement("INSERT INTO `oc ... )", ["*** sensitive  ... 2], [1,2,2,2,1])
 4. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 280
    Doctrine\DBAL\Query\QueryBuilder->execute()
 5. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 326
    OC\DB\QueryBuilder\QueryBuilder->execute()
 6. /var/www/vhosts/*****/html/main/nextcloud/lib/public/AppFramework/Db/QBMapper.php line 138
    OC\DB\QueryBuilder\QueryBuilder->executeStatement()
 7. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/SessionService.php line 100
    OCP\AppFramework\Db\QBMapper->insert(["OCA\\Text\\Db\ ... "])
 8. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/ApiService.php line 129
    OCA\Text\Service\SessionService->initSession("*** sensitive parameters replaced ***", "*** sensitive parameters replaced ***")
 9. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Controller/SessionController.php line 61
    OCA\Text\Service\ApiService->create("*** sensitive parameters replaced ***")
10. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 230
    OCA\Text\Controller\SessionController->create("*** sensitive parameters replaced ***")
11. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 137
    OC\AppFramework\Http\Dispatcher->executeController(["OCA\\Text\\Con ... "], "create")
12. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/App.php line 183
    OC\AppFramework\Http\Dispatcher->dispatch(["OCA\\Text\\Con ... "], "create")
13. /var/www/vhosts/*****/html/main/nextcloud/lib/private/Route/Router.php line 315
    OC\AppFramework\App::main("OCA\\Text\\Cont ... r", "create", ["OC\\AppFramewo ... "], ["text.Session.create"])
14. /var/www/vhosts/*****/html/main/nextcloud/lib/base.php line 1056
    OC\Route\Router->match("/apps/text/session/create")
15. /var/www/vhosts/*****/html/main/nextcloud/index.php line 36
    OC::handleRequest()

Caused by:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'oc_text_sessions.PRIMARY' at <<closure>>

 0. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Driver/PDO/Statement.php line 101
    PDOStatement->execute("*** sensitive parameters replaced ***")
 1. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Connection.php line 1153
    Doctrine\DBAL\Driver\PDO\Statement->execute()
 2. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/Connection.php line 297
    Doctrine\DBAL\Connection->executeStatement("INSERT INTO `oc ... )", ["*** sensitive  ... 2], [1,2,2,2,1])
 3. /var/www/vhosts/*****/html/main/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php line 354
    OC\DB\Connection->executeStatement("INSERT INTO `oc ... )", ["*** sensitive  ... 2], [1,2,2,2,1])
 4. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 280
    Doctrine\DBAL\Query\QueryBuilder->execute()
 5. /var/www/vhosts/*****/html/main/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php line 326
    OC\DB\QueryBuilder\QueryBuilder->execute()
 6. /var/www/vhosts/*****/html/main/nextcloud/lib/public/AppFramework/Db/QBMapper.php line 138
    OC\DB\QueryBuilder\QueryBuilder->executeStatement()
 7. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/SessionService.php line 100
    OCP\AppFramework\Db\QBMapper->insert(["OCA\\Text\\Db\ ... "])
 8. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Service/ApiService.php line 129
    OCA\Text\Service\SessionService->initSession("*** sensitive parameters replaced ***", "*** sensitive parameters replaced ***")
 9. /var/www/vhosts/*****/html/main/nextcloud/apps/text/lib/Controller/SessionController.php line 61
    OCA\Text\Service\ApiService->create("*** sensitive parameters replaced ***")
10. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 230
    OCA\Text\Controller\SessionController->create("*** sensitive parameters replaced ***")
11. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/Http/Dispatcher.php line 137
    OC\AppFramework\Http\Dispatcher->executeController(["OCA\\Text\\Con ... "], "create")
12. /var/www/vhosts/*****/html/main/nextcloud/lib/private/AppFramework/App.php line 183
    OC\AppFramework\Http\Dispatcher->dispatch(["OCA\\Text\\Con ... "], "create")
13. /var/www/vhosts/*****/html/main/nextcloud/lib/private/Route/Router.php line 315
    OC\AppFramework\App::main("OCA\\Text\\Cont ... r", "create", ["OC\\AppFramewo ... "], ["text.Session.create"])
14. /var/www/vhosts/*****/html/main/nextcloud/lib/base.php line 1056
    OC\Route\Router->match("/apps/text/session/create")
15. /var/www/vhosts/*****/html/main/nextcloud/index.php line 36
    OC::handleRequest()

PUT /index.php/apps/text/session/create
from 212.201.53.231 by ***** at 2023-05-25T09:01:22+00:00

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

<?php
$CONFIG = array (
  'instanceid' => '*****',
  'passwordsalt' => '*****',
  'secret' => '*****',
  'trusted_domains' => 
  array (
    0 => '*****',
    1 => '*****',
    2 => '*****',
    3 => '*****',
    4 => '*****',
    5 => '*****',
    6 => '*****',
    7 => '*****',
    8 => '*****',
  ),
  'datadirectory' => '/var/www/vhosts/*****/html/main/nextcloud-data',
  'overwrite.cli.url' => '*****',
  'dbtype' => 'mysql',
  'version' => '26.0.1.1',
  'dbname' => '*****',
  'dbhost' => '127.0.0.1:3307',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '*****',
  'dbpassword' => '*****',
  'installed' => true,
  'maintenance' => false,
  'mail_from_address' => 'cloud',
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_domain' => '*****',
  'theme' => '',
  'loglevel' => 2,
  'log_rotate_size' => 104857600,
  'updater.release.channel' => 'stable',
  'mail_smtpauth' => 1,
  'mail_smtpsecure' => 'ssl',
  'mail_smtphost' => '*****',
  'mail_smtpport' => '465',
  'mail_smtpname' => '*****',
  'mail_smtppassword' => '*****',
  'app_install_overwrite' => 
  array (
    0 => 'calendar',
    1 => 'keeporsweep',
    2 => 'sensorlogger',
  ),
  'encryption.legacy_format_support' => false,
  'encryption.key_storage_migrated' => false,
  'mail_sendmailmode' => 'smtp',
  'default_phone_region' => 'DE',
);

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

no output

I also get an error when trying to share a folder. Here the short form:

Error creating the share: An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘0’ for key ‘oc_share.PRIMARY’

Both problems seem to be solved. Don’t know why, but in the database the id-columns did miss the auto_increment option. I set them and now it seems to work properly.