{"record":{"id":"a2738216a93f0e4c","repo":"theonedev/onedev","slug":"data-version-mismatch-app-data-version-s-db-da","errorCode":null,"errorMessage":"Data version mismatch (app data version: %s, db data version: %s)","messagePattern":"Data version mismatch \\(app data version: (.+?), db data version: (.+?)\\)","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"critical","filePath":"server-core/src/main/java/io/onedev/server/data/DefaultDataService.java","lineNumber":236,"sourceCode":"\t\t\t\t\t\tlogger.error(\"Error executing sql: \" + sql, e);\n\t\t\t\t\tif (failOnError) \n\t\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (SQLException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\t\n\t@Override\n\tpublic String checkDataVersion(Connection conn, boolean allowEmptyDB) {\n\t\tString dbDataVersion = readDbDataVersion(conn);\n\t\t\n\t\tif (!allowEmptyDB && dbDataVersion == null) \n\t\t\tthrow new ExplicitException(\"Database is not populated yet\");\n\t\tString appDataVersion = MigrationHelper.getVersion(DataMigrator.class);\n\t\tif (dbDataVersion != null && !dbDataVersion.equals(appDataVersion)) {\n\t\t\tthrow new ExplicitException(String.format(\"Data version mismatch (app data version: %s, db data version: %s)\", \n\t\t\t\t\tappDataVersion, dbDataVersion));\n\t\t}\n\t\treturn dbDataVersion;\n\t}\n\t\n\t@Override\n\tpublic void populateDatabase(Connection conn) {\n\t\tif (hibernateConfig.isHSQLDialect()) \n\t\t\texecute(conn, Lists.newArrayList(\"SET DATABASE TRANSACTION CONTROL MVCC\"), true);\n\t\t\n\t\tString dbDataVersion = checkDataVersion(conn, true);\n\t\t\n\t\tif (dbDataVersion == null) {\n\t\t\tFile tempFile = null;\n        \ttry {\n            \ttempFile = FileUtils.createTempFile(\"schema\", \".sql\");\n\t        \tnew SchemaExport().setOutputFile(tempFile.getAbsolutePath())\n\t        \t\t\t.setFormat(false).createOnly(EnumSet.of(TargetType.SCRIPT), getMetadata());","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/data/DefaultDataService.java#L218-L254","documentation":"checkDataVersion compares the data version stored in the DB with the app data version (MigrationHelper.getVersion(DataMigrator.class)). If they differ, the database was created/migrated by a different OneDev version, so it throws this ExplicitException with both versions.","triggerScenarios":"Starting or migrating OneDev when the DB's version row (from ModelVersion table) does not equal the version expected by the running application's DataMigrator chain.","commonSituations":"Downgrading OneDev after the DB was migrated to a newer schema; restoring a DB backup from a different OneDev version; running multiple OneDev versions against the same database.","solutions":["Run the matching OneDev version that the DB was migrated with, or a newer one that can upgrade it","Restore a DB backup consistent with the current application version","Never downgrade below the version that last migrated the database","Check the version via the ModelVersion table and pick the correct release"],"exampleFix":"// before\n# running OneDev 10.0 against a DB migrated by 11.2\n// after\n# download and run OneDev 11.2 (or newer) so the data versions match","handlingStrategy":"validation","validationCode":"String dbVersion = queryScalar(conn, \"select version from model_version\");\nif (dbVersion != null && !dbVersion.equals(expectedAppDataVersion)) useMatchingOneDevVersion(dbVersion);","typeGuard":null,"tryCatchPattern":"try { startServer(); } catch (ExplicitException e) { if (e.getMessage().contains(\"Data version mismatch\")) { parseVersions(e); runCompatibleRelease(); } }","preventionTips":["Never downgrade below the version that last migrated the DB","Restore DB backups only into instances of matching version","Run one OneDev version per database","Record the app version alongside each backup"],"tags":["database","version-mismatch","migration"],"backgroundTag":"data-version-mismatch","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}