{"record":{"id":"e52ea0289228e129","repo":"theonedev/onedev","slug":"unable-to-upgrade-specified-installation-as-data-v","errorCode":null,"errorMessage":"Unable to upgrade specified installation as data version of application and database is not the same","messagePattern":"Unable to upgrade specified installation as data version of application and database is not the same","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java","lineNumber":307,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tvar callable = new Callable<Void>() {\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic Void call() {\n\t\t\t\t\t\t\tvar newAppDataVersion = parseInt(MigrationHelper.getVersion(DataMigrator.class));\n\t\t\t\t\t\t\tvar dataVersion = getDataVersion(upgradeDir);\n\t\t\t\t\t\t\tvar oldAppDataVersion = dataVersion.app;\n\t\t\t\t\t\t\tvar dbDataVersion = dataVersion.db;\n\t\t\t\t\t\t\tif (dbDataVersion == 0) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Unable to upgrade specified installation as database is not populated yet\");\n\t\t\t\t\t\t\tif (dbDataVersion == -1) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Unable to upgrade specified installation due to above error\");\n\t\t\t\t\t\t\tif (dbDataVersion != oldAppDataVersion && dbDataVersion != newAppDataVersion) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Unable to upgrade specified installation as data version of application and database is not the same\");\n\t\t\t\t\t\t\tif (newAppDataVersion < oldAppDataVersion) \n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"OneDev program is too old, please use a newer version\");\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tString timestamp = DateTimeFormat.forPattern(BACKUP_DATETIME_FORMAT).print(new DateTime());\n\t\t\t\t\t\t\tFile programBackup = new File(upgradeDir, \"site/program-backup/\" + timestamp);\n\t\t\t\t\t\t\tFileUtils.createDir(programBackup);\n\n\t\t\t\t\t\t\tlogger.info(\"Backing up old program files as {}...\", programBackup.getAbsolutePath());\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tfor (File each : upgradeDir.listFiles()) {\n\t\t\t\t\t\t\t\t\tif (each.isFile()) {\n\t\t\t\t\t\t\t\t\t\tFileUtils.copyFileToDirectory(each, programBackup);\n\t\t\t\t\t\t\t\t\t} else if (!each.getName().equals(\"temp\")\n\t\t\t\t\t\t\t\t\t\t\t&& !each.getName().equals(\"site\")\n\t\t\t\t\t\t\t\t\t\t\t&& !each.getName().equals(\"internaldb\")) {\n\t\t\t\t\t\t\t\t\t\tFileUtils.copyDirectoryToDirectory(each, programBackup);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java#L289-L325","documentation":"The upgrade command requires the database's data version to match either the old application data version (from the upgrade dir) or the new application data version being upgraded to. If dbDataVersion differs from both, the application and database are out of sync in an unsupported way and the upgrade aborts with this ExplicitException.","triggerScenarios":"Running 'upgrade' when dbDataVersion != oldAppDataVersion && dbDataVersion != newAppDataVersion — e.g. skipping multiple intermediate versions, restoring a database of a different version into the site dir, or mixing site directories and databases from different installations.","commonSituations":"Upgrading across several OneDev versions in one hop; pairing a site/upgrade directory from one install with a database from another; restoring an old backup and then attempting a direct upgrade to the latest version.","solutions":["Upgrade step by step through intermediate OneDev versions so the database migrates version by version to match.","Ensure the site directory and database belong to the same installation and version.","Check the recorded versions in upgrade logs to see exactly which versions are mismatched.","Restore a consistent backup matching the target version rather than mixing versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// upgrade only one version step at a time\nif (dbDataVersion != oldAppDataVersion && dbDataVersion != newAppDataVersion)\n    throw new IllegalStateException(\"Upgrade through intermediate versions first\");","typeGuard":null,"tryCatchPattern":"try {\n    upgrade.call();\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"data version of application and database is not the same\"))\n    logger.error(\"App and DB versions diverge; upgrade step-by-step via intermediate versions\");\n}","preventionTips":["Upgrade through each intermediate version instead of jumping multiple releases.","Keep the site directory and database from the same installation together.","Record the current OneDev version and data version before any upgrade.","Never mix a restored database backup with a different version's site directory."],"tags":["upgrade","versioning","migration","database"],"backgroundTag":"database-schema-version-mismatch","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"}