{"record":{"id":"2848a6a7b48cadf9","repo":"theonedev/onedev","slug":"unable-to-upgrade-specified-installation-as-databa","errorCode":null,"errorMessage":"Unable to upgrade specified installation as database is not populated yet","messagePattern":"Unable to upgrade specified installation as database is not populated yet","errorType":"console","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java","lineNumber":303,"sourceCode":"\t\t\t\t\tString hibernateProps = FileUtils.readFileToString(hibernatePropsFile, UTF_8);\n\t\t\t\t\tif (hibernateProps.contains(\"sampledb\")) {\n\t\t\t\t\t\thibernateProps = Strings.CS.replace(hibernateProps, \"sampledb\", \"internaldb\");\n\t\t\t\t\t\twriteStringToFile(hibernatePropsFile, hibernateProps, UTF_8);\n\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\")","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java#L285-L321","documentation":"The upgrade command reads the data version recorded in the database (dbDataVersion) from the upgrade directory and validates it before migrating. A value of 0 means the database was never populated with version metadata (setup never ran or the DB is empty), so the upgrade aborts with this ExplicitException.","triggerScenarios":"Running the 'upgrade' command on an installation whose database has no recorded data version (getDataVersion returns dbDataVersion == 0) — typically an empty or never-initialized database.","commonSituations":"Upgrading a freshly created site directory before first launch/setup; pointing the upgrade at a wrong database that is empty; a broken installation where version metadata tables were never created.","solutions":["Start the current OneDev version once and complete setup so the database is populated, then upgrade.","Verify the upgrade is targeting the correct site directory and database that contains existing data.","Check upgrade logs / getDataVersion output to confirm how the version was read from the upgrade dir.","If the DB is genuinely empty, skip the upgrade and just start the new version (it will initialize from scratch)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure DB is populated before upgrading\nif (!databaseHasData(siteDir))\n    throw new IllegalStateException(\"Database empty: start current version and complete setup before upgrading\");","typeGuard":null,"tryCatchPattern":"try {\n    upgrade.call();\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"database is not populated yet\"))\n    logger.error(\"Initialize the database with the current version before upgrading\");\n}","preventionTips":["Never run upgrade on a brand-new/empty site directory; start the app once first.","Verify the upgrade script points at the directory containing real data.","Confirm version metadata exists in the DB before automating upgrades."],"tags":["upgrade","database","migration","versioning"],"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-14T05:17:10.506Z"}