{"record":{"id":"34dd27a2333757cc","repo":"theonedev/onedev","slug":"illegal-data-version-format-in-database","errorCode":null,"errorMessage":"Illegal data version format in database","messagePattern":"Illegal data version format in database","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"server-core/src/main/java/io/onedev/server/data/DefaultDataService.java","lineNumber":309,"sourceCode":"\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\n\tprivate File getVersionFile(File dataDir) {\n\t\tFile versionFile = new File(dataDir, ModelVersion.class.getSimpleName() + \"s.xml\");\n\t\tif (!versionFile.exists())\n\t\t\tversionFile = new File(dataDir, \"VersionTables.xml\");\n\t\treturn versionFile;","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/data/DefaultDataService.java#L291-L327","documentation":"readDbDataVersion expects exactly one row in the ModelVersion table. After reading the first row's version value, if resultset.next() returns true again, multiple version rows exist, which is an illegal format, so it throws 'Illegal data version format in database'.","triggerScenarios":"The ModelVersion table contains more than one row, e.g. from duplicate inserts during a botched restore, manual data import, or a migration bug.","commonSituations":"Restoring backup data twice without cleaning the DB, merging databases, or manual SQL manipulation of the version table.","solutions":["Delete the duplicate rows so exactly one version row remains: delete from <ModelVersion table> where id != (select min(id) ...)","Verify the remaining version value matches the OneDev version that wrote the DB","If unsure, drop/recreate the DB and restore from a clean backup","Re-run the restore with the restore-db script from the correct backup"],"exampleFix":"-- keep only one version row\ndelete from model_version where id not in (select min(id) from model_version);","handlingStrategy":"validation","validationCode":"int rows = countRows(conn, \"model_version\");\nif (rows != 1) dedupeOrRestoreModelVersionTable();","typeGuard":null,"tryCatchPattern":"try { migrate(); } catch (RuntimeException e) { if (e.getMessage().contains(\"Illegal data version format\")) { deleteDuplicateVersionRows(conn); } }","preventionTips":["Never restore the same backup twice without cleaning the DB","Avoid manual INSERTs into the version table","Keep one version row — treat the table as single-row invariant","Validate DB state after any manual data import"],"tags":["database","corrupt-state","duplicate-rows"],"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"}