File entry could not be inserted but could also not be selected with getId()

Nextcloud version: 16.0.0
Operating system and version: Linux a2f21 3.16.0-7-amd64 #1 SMP Debian 3.16.59-1 (2018-10-03) x86_64
Apache or nginx version: Apache (can’t find out the version, since it’s a webhosting)
PHP version: 7.3

The issue you are facing:
Nextcloud run fine for over 2 years now and without any config changes or anything else, I get this error when I try to access the login page:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Is this the first time you’ve seen this error?: Y

Steps to replicate it:

  1. Try to open the login screen of my nextcloud

The output of your Nextcloud log in Admin > Logging:

Since I can’t access my nextcloud, here is the log from /data/nextcloud.log

{
   "reqId":"gVwUHSIQ7hYd4SBTsMMt",
   "level":3,
   "time":"2019-04-28T12:47:18+00:00",
   "remoteAddr":"217.80.120.161",
   "user":"--",
   "app":"index",
   "method":"GET",
   "url":"\/index.php\/login",
   "message":{
      "Exception":"RuntimeException",
      "Message":"File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.",
      "Code":0,
      "Trace":[
         {
            "file":"\/Cloud\/lib\/private\/Files\/Cache\/Cache.php",
            "line":238,
            "function":"insert",
            "class":"OC\\Files\\Cache\\Cache",
            "type":"->",
            "args":[
               "appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps",
               {
                  "mimetype":"application\/octet-stream",
                  "mtime":1556323682,
                  "size":0,
                  "etag":"da62a6db9afff45f5418770faa8793f7",
                  "storage_mtime":1556323682,
                  "permissions":27,
                  "parent":43481,
                  "checksum":"",
                  "path":"appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps",
                  "name":"merged-template-prepend.js.deps"
               }
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/Cache\/Scanner.php",
            "line":292,
            "function":"put",
            "class":"OC\\Files\\Cache\\Cache",
            "type":"->",
            "args":[
               "appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps",
               {
                  "mimetype":"application\/octet-stream",
                  "mtime":1556323682,
                  "size":0,
                  "etag":"da62a6db9afff45f5418770faa8793f7",
                  "storage_mtime":1556323682,
                  "permissions":27,
                  "parent":43481,
                  "checksum":""
               }
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/Cache\/Scanner.php",
            "line":221,
            "function":"addToCache",
            "class":"OC\\Files\\Cache\\Scanner",
            "type":"->",
            "args":[
               "appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps",
               {
                  "mimetype":"application\/octet-stream",
                  "mtime":1556323682,
                  "size":0,
                  "etag":"da62a6db9afff45f5418770faa8793f7",
                  "storage_mtime":1556323682,
                  "permissions":27,
                  "parent":43481,
                  "checksum":""
               },
               -1
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/Cache\/Scanner.php",
            "line":336,
            "function":"scanFile",
            "class":"OC\\Files\\Cache\\Scanner",
            "type":"->",
            "args":[
               "appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps",
               3,
               43481,
               false,
               true
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/View.php",
            "line":1332,
            "function":"scan",
            "class":"OC\\Files\\Cache\\Scanner",
            "type":"->",
            "args":[
               "appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps",
               false
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/View.php",
            "line":1376,
            "function":"getCacheEntry",
            "class":"OC\\Files\\View",
            "type":"->",
            "args":[
               {
                  "cache":{
                     "__class__":"OC\\Files\\Cache\\Cache"
                  },
                  "scanner":{
                     "__class__":"OC\\Files\\Cache\\Scanner"
                  },
                  "watcher":null,
                  "propagator":null,
                  "updater":null,
                  "__class__":"OCA\\Files_Trashbin\\Storage"
               },
               "appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps",
               "\/appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/Node\/Root.php",
            "line":198,
            "function":"getFileInfo",
            "class":"OC\\Files\\View",
            "type":"->",
            "args":[
               "\/appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/Node\/Folder.php",
            "line":134,
            "function":"get",
            "class":"OC\\Files\\Node\\Root",
            "type":"->",
            "args":[
               "\/appdata_oc9vh5te2zmf\/js\/core\/merged-template-prepend.js.deps"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Files\/SimpleFS\/SimpleFolder.php",
            "line":73,
            "function":"get",
            "class":"OC\\Files\\Node\\Folder",
            "type":"->",
            "args":[
               "merged-template-prepend.js.deps"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Template\/JSCombiner.php",
            "line":122,
            "function":"getFile",
            "class":"OC\\Files\\SimpleFS\\SimpleFolder",
            "type":"->",
            "args":[
               "merged-template-prepend.js.deps"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Template\/JSCombiner.php",
            "line":100,
            "function":"isCached",
            "class":"OC\\Template\\JSCombiner",
            "type":"->",
            "args":[
               "merged-template-prepend.js.deps",
               {
                  "__class__":"OC\\Files\\SimpleFS\\SimpleFolder"
               }
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Template\/JSResourceLocator.php",
            "line":114,
            "function":"process",
            "class":"OC\\Template\\JSCombiner",
            "type":"->",
            "args":[
               "\/Cloud",
               "core\/js\/merged-template-prepend.json",
               "core"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Template\/JSResourceLocator.php",
            "line":70,
            "function":"cacheAndAppendCombineJsonIfExist",
            "class":"OC\\Template\\JSResourceLocator",
            "type":"->",
            "args":[
               "\/Cloud",
               "core\/js\/merged-template-prepend.json"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Template\/ResourceLocator.php",
            "line":78,
            "function":"doFind",
            "class":"OC\\Template\\JSResourceLocator",
            "type":"->",
            "args":[
               "js\/merged-template-prepend"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/TemplateLayout.php",
            "line":332,
            "function":"find",
            "class":"OC\\Template\\ResourceLocator",
            "type":"->",
            "args":[
               [
                  "core\/js\/dist\/main",
                  "js\/merged-template-prepend",
                  "search\/js\/search",
                  "core\/l10n\/en",
                  "js\/backgroundjobs",
                  "core\/js\/dist\/share_backend",
                  "files_pdfviewer\/l10n\/en",
                  "files_pdfviewer\/js\/previewplugin",
                  "files_rightclick\/l10n\/en",
                  "files_rightclick\/js\/script",
                  "files_videoplayer\/l10n\/en",
                  "files_videoplayer\/js\/main",
                  "gallery\/l10n\/en",
                  "search\/l10n\/en",
                  "search\/js\/searchprovider",
                  "js\/files\/fileinfo",
                  "js\/files\/client",
                  "core\/js\/merged-login"
               ]
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/TemplateLayout.php",
            "line":160,
            "function":"findJavascriptFiles",
            "class":"OC\\TemplateLayout",
            "type":"::",
            "args":[
               [
                  "core\/js\/dist\/main",
                  "js\/merged-template-prepend",
                  "search\/js\/search",
                  "core\/l10n\/en",
                  "js\/backgroundjobs",
                  "core\/js\/dist\/share_backend",
                  "files_pdfviewer\/l10n\/en",
                  "files_pdfviewer\/js\/previewplugin",
                  "files_rightclick\/l10n\/en",
                  "files_rightclick\/js\/script",
                  "files_videoplayer\/l10n\/en",
                  "files_videoplayer\/js\/main",
                  "gallery\/l10n\/en",
                  "search\/l10n\/en",
                  "search\/js\/searchprovider",
                  "js\/files\/fileinfo",
                  "js\/files\/client",
                  "core\/js\/merged-login"
               ]
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/legacy\/template.php",
            "line":183,
            "function":"__construct",
            "class":"OC\\TemplateLayout",
            "type":"->",
            "args":[
               "guest",
               "core"
            ]
         },
         {
            "file":"\/Cloud\/lib\/public\/AppFramework\/Http\/TemplateResponse.php",
            "line":160,
            "function":"fetchPage",
            "class":"OC_Template",
            "type":"->",
            "args":[
               {
                  "messages":[

                  ],
                  "loginName":"",
                  "user_autofocus":true,
                  "login_form_autocomplete":"on",
                  "resetPasswordLink":"",
                  "canResetPassword":true,
                  "alt_login":[

                  ],
                  "throttle_delay":0
               }
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/AppFramework\/Http\/Dispatcher.php",
            "line":119,
            "function":"render",
            "class":"OCP\\AppFramework\\Http\\TemplateResponse",
            "type":"->",
            "args":[

            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/AppFramework\/App.php",
            "line":126,
            "function":"dispatch",
            "class":"OC\\AppFramework\\Http\\Dispatcher",
            "type":"->",
            "args":[
               {
                  "__class__":"OC\\Core\\Controller\\LoginController"
               },
               "showLoginForm"
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/AppFramework\/Routing\/RouteActionHandler.php",
            "line":47,
            "function":"main",
            "class":"OC\\AppFramework\\App",
            "type":"::",
            "args":[
               "OC\\Core\\Controller\\LoginController",
               "showLoginForm",
               {
                  "__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"
               },
               {
                  "_route":"core.login.showLoginForm"
               }
            ]
         },
         {
            "function":"__invoke",
            "class":"OC\\AppFramework\\Routing\\RouteActionHandler",
            "type":"->",
            "args":[
               {
                  "_route":"core.login.showLoginForm"
               }
            ]
         },
         {
            "file":"\/Cloud\/lib\/private\/Route\/Router.php",
            "line":297,
            "function":"call_user_func",
            "args":[
               {
                  "__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"
               },
               {
                  "_route":"core.login.showLoginForm"
               }
            ]
         },
         {
            "file":"\/Cloud\/lib\/base.php",
            "line":975,
            "function":"match",
            "class":"OC\\Route\\Router",
            "type":"->",
            "args":[
               "\/login"
            ]
         },
         {
            "file":"\/Cloud\/index.php",
            "line":42,
            "function":"handleRequest",
            "class":"OC",
            "type":"::",
            "args":[

            ]
         }
      ],
      "File":"\/Cloud\/lib\/private\/Files\/Cache\/Cache.php",
      "Line":305,
      "CustomMessage":"--"
   },
   "userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.108 Safari\/537.36",
   "version":"16.0.0.9"
}

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

<?php
$CONFIG = array (
  'instanceid' => 'removed',
  'passwordsalt' => 'removed',
  'secret' => 'removed',
  'trusted_domains' => 
  array (
    0 => 'removed',
    1 => 'removed',
    2 => 'removed',
  ),
  'datadirectory' => '/Cloud/data',
  'overwrite.cli.url' => 'removed',
  'dbtype' => 'mysql',
  'version' => '16.0.0.9',
  'dbname' => 'removed',
  'dbhost' => 'removed',
  'dbport' => '3306',
  'dbtableprefix' => 'removed',
  'dbuser' => 'removed',
  'dbpassword' => 'removed',
  'logtimezone' => 'UTC',
  'installed' => true,
  'forcessl' => true,
  'theme' => '',
  'mail_from_address' => 'removed',
  'mail_smtpmode' => 'smtp',
  'mail_domain' => 'removed',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpsecure' => 'tls',
  'mail_smtpauth' => 1,
  'mail_smtpport' => '587',
  'mail_smtpname' => 'removed',
  'mail_smtppassword' => 'removed',
  'maintenance' => false,
  'loglevel' => 0,
  'updater.release.channel' => 'stable',
  'mail_smtphost' => 'removed',
  'updater.secret' => 'removed',
);

FWIW, I had almost the exact same error - well, same error with a different file trying to be inserted into cache.

After a lot of rummaging about I noticed that the filecache table had lost its AUTOINCREMENT attribute. How? Not the least idea.

But on copying the table, then deleting all rows, defining the auto increment, I was then able to log on. Clearly it will need to rebuild the cache so will take extra time on the first access.

Here is how I personally solved this issue:

STEP #1:
show table status like "oc_filecache";

This shows Auto_increment : NULL

STEP #2
DELETE from oc_filecache WHERE fileid IN (1);

STEP #3
ALTER TABLE oc_filecache CHANGE fileid fileid INT(1)AUTO_INCREMENT;

then check again show table status like "oc_filecache"; and you should now see correct value.

Hope it helps!

1 Like

Thank you so much! Got my Nextcloud working again with that :smiley:

Thanx for the issue.

How to do this with PostgreSQL ?

it shows me :

ERREUR: erreur de syntaxe sur ou près de « table »
LIGNE 1 : show table status like ‘oc_filecache’;