{"record":{"id":"8f1739046db64412","repo":"theonedev/onedev","slug":"no-data-version-found-in-database-this-is-normall","errorCode":null,"errorMessage":"No data version found in database: this is normally caused by unsuccessful restore/upgrade, please clean the database and try again","messagePattern":"No data version found in database: this is normally caused by unsuccessful restore/upgrade, please clean the database and try again","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"server-core/src/main/java/io/onedev/server/data/DefaultDataService.java","lineNumber":304,"sourceCode":"\t\treturn physicalNamingStrategy.toPhysicalTableName(identifier, environment).getText();\n\t}\n\t\n\t@Override\n\tpublic String getColumnName(String fieldName) {\n\t\tJdbcEnvironment environment = getMetadata().getDatabase()\n\t\t\t\t.getServiceRegistry().getService(JdbcEnvironment.class);\n\t\tIdentifier identifier = Identifier.toIdentifier(fieldName);\n\t\treturn physicalNamingStrategy.toPhysicalColumnName(identifier, environment).getText();\n\t}\n\t\n\tprivate String readDbDataVersion(Connection conn) {\n\t\ttry {\n\t\t\tvar versionTableName = getTableName(ModelVersion.class);\n\t\t\tif (tableExists(conn, versionTableName)) {\n\t\t\t\ttry (\tStatement stmt = conn.createStatement();\n\t\t\t\t\t\t ResultSet resultset = stmt.executeQuery(\"select \" + getColumnName(ModelVersion.PROP_VERSION_COLUMN) + \" from \" + versionTableName)) {\n\t\t\t\t\tif (!resultset.next()) {\n\t\t\t\t\t\tthrow new RuntimeException(\"No data version found in database: this is normally caused \"\n\t\t\t\t\t\t\t\t+ \"by unsuccessful restore/upgrade, please clean the database and try again\");\n\t\t\t\t\t}\n\t\t\t\t\tString dataVersion = resultset.getString(1);\n\t\t\t\t\tif (resultset.next())\n\t\t\t\t\t\tthrow new RuntimeException(\"Illegal data version format in database\");\n\t\t\t\t\treturn dataVersion;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\tif (e.getMessage() != null && e.getMessage().contains(\"ORA-00942\")) \n\t\t\t\treturn null;\n\t\t\telse\n\t\t\t\tthrow ExceptionUtils.unchecked(e);\n\t\t}\n\t}\n","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/data/DefaultDataService.java#L286-L322","documentation":"readDbDataVersion selects the version column from the ModelVersion table. If the table exists but contains zero rows, the database is in a partially restored/upgraded state, so it throws a RuntimeException instructing the user to clean the database and try again.","triggerScenarios":"The ModelVersion table exists but the 'select version from <table>' result set is empty — e.g. schema created but the version insert never committed.","commonSituations":"Interrupted restore or upgrade, manual truncation of tables, DB transaction rolled back after DDL but before the version row insert.","solutions":["Back up any needed data, then drop and recreate the database","Re-run the restore procedure (restore-db.sh/bat) from a known-good backup","Start OneDev fresh so it populates the DB from scratch","Inspect the restore/upgrade logs to find where it failed before retrying"],"exampleFix":"-- before retrying\ndrop database onedev;\ncreate database onedev;\n-- then run restore-db.sh with a good backup or start OneDev fresh","handlingStrategy":"validation","validationCode":"// before startup checks\nif (tableExists(conn, \"model_version\") && countRows(conn, \"model_version\") == 0) cleanAndRestoreDb();","typeGuard":null,"tryCatchPattern":"try { migrate(); } catch (RuntimeException e) { if (e.getMessage().contains(\"No data version found in database\")) { dropAndRecreateDb(); rerunRestore(); } }","preventionTips":["Let restore/upgrade scripts run to completion — avoid killing them","Verify backups restore fully before deleting originals","Monitor restore logs for errors","Only manipulate the version table with full understanding of its role"],"tags":["database","corrupt-state","restore"],"backgroundTag":"empty-result-set","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}