{"record":{"id":"59c6b697827a3b9b","repo":"theonedev/onedev","slug":"database-is-not-populated-yet","errorCode":null,"errorMessage":"Database is not populated yet","messagePattern":"Database is not populated yet","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/data/DefaultDataService.java","lineNumber":233,"sourceCode":"\t\t\t\t\tif (sql.contains(\" drop \") && e.getMessage() != null)\n\t\t\t\t\t\tlogger.warn(e.getMessage());\n\t\t\t\t\telse\n\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 {","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/data/DefaultDataService.java#L215-L251","documentation":"checkDataVersion reads the data version recorded in the database. If the database contains no version row and empty databases are not allowed, OneDev concludes the schema has never been populated and throws this ExplicitException to stop startup/migration against an empty DB.","triggerScenarios":"dbDataVersion calls checkDataVersion(conn, allowEmptyDB=false) against a freshly created, empty database (the ModelVersion table is missing or has no rows).","commonSituations":"Pointing OneDev at a brand-new empty database instead of letting it initialize; a restore that created the schema but inserted no version row; wrong JDBC URL pointing to an empty DB instance.","solutions":["Let OneDev initialize the database itself on first startup (no manual pre-creation needed against an empty DB)","Verify the JDBC URL/credentials point at the actual OneDev database, not an empty one","Re-run the restore/upgrade procedure if a previous restore left the DB empty","Drop and recreate the DB and start OneDev fresh if data is not needed"],"exampleFix":"// before\njdbcUrl=jdbc:h2:/var/lib/onedev/database/wrong_empty_db\n// after\njdbcUrl=jdbc:h2:/var/lib/onedev/database/onedev","handlingStrategy":"validation","validationCode":"// check DB is populated before pointing OneDev at it\nboolean populated = tableExists(conn, \"model_version\") && hasRows(conn, \"model_version\");","typeGuard":null,"tryCatchPattern":"try { startServer(); } catch (ExplicitException e) { if (e.getMessage().equals(\"Database is not populated yet\")) { verifyJdbcUrl(); letOneDevInitialize(); } }","preventionTips":["Let OneDev create and initialize its database on first startup","Double-check JDBC URLs when multiple DB instances exist","Never pre-create an empty DB and expect it to contain data","Keep DB connection config in version-controlled templates"],"tags":["database","initialization","data-version"],"backgroundTag":"database-not-populated","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"}