theonedev/onedev · critical · RuntimeException

No data version found in database: this is normally caused b

Error message

No data version found in database: this is normally caused by unsuccessful restore/upgrade, please clean the database and try again

What it means

readDbDataVersion selects the version column from the ModelVersion table. If the table exists but contains zero rows, the database is in a partially restored/upgraded state, so it throws a RuntimeException instructing the user to clean the database and try again.

Source

Thrown at server-core/src/main/java/io/onedev/server/data/DefaultDataService.java:304

		return physicalNamingStrategy.toPhysicalTableName(identifier, environment).getText();
	}
	
	@Override
	public String getColumnName(String fieldName) {
		JdbcEnvironment environment = getMetadata().getDatabase()
				.getServiceRegistry().getService(JdbcEnvironment.class);
		Identifier identifier = Identifier.toIdentifier(fieldName);
		return physicalNamingStrategy.toPhysicalColumnName(identifier, environment).getText();
	}
	
	private String readDbDataVersion(Connection conn) {
		try {
			var versionTableName = getTableName(ModelVersion.class);
			if (tableExists(conn, versionTableName)) {
				try (	Statement stmt = conn.createStatement();
						 ResultSet resultset = stmt.executeQuery("select " + getColumnName(ModelVersion.PROP_VERSION_COLUMN) + " from " + versionTableName)) {
					if (!resultset.next()) {
						throw new RuntimeException("No data version found in database: this is normally caused "
								+ "by unsuccessful restore/upgrade, please clean the database and try again");
					}
					String dataVersion = resultset.getString(1);
					if (resultset.next())
						throw new RuntimeException("Illegal data version format in database");
					return dataVersion;
				}
			} else {
				return null;
			}
		} catch (Exception e) {
			if (e.getMessage() != null && e.getMessage().contains("ORA-00942")) 
				return null;
			else
				throw ExceptionUtils.unchecked(e);
		}
	}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Back up any needed data, then drop and recreate the database
  2. Re-run the restore procedure (restore-db.sh/bat) from a known-good backup
  3. Start OneDev fresh so it populates the DB from scratch
  4. Inspect the restore/upgrade logs to find where it failed before retrying

Example fix

-- before retrying
drop database onedev;
create database onedev;
-- then run restore-db.sh with a good backup or start OneDev fresh
Defensive patterns

Strategy: validation

Validate before calling

// before startup checks
if (tableExists(conn, "model_version") && countRows(conn, "model_version") == 0) cleanAndRestoreDb();

Try / catch

try { migrate(); } catch (RuntimeException e) { if (e.getMessage().contains("No data version found in database")) { dropAndRecreateDb(); rerunRestore(); } }

Prevention

When it happens

Trigger: The ModelVersion table exists but the 'select version from <table>' result set is empty — e.g. schema created but the version insert never committed.

Common situations: Interrupted restore or upgrade, manual truncation of tables, DB transaction rolled back after DDL but before the version row insert.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/8f1739046db64412. Report an issue: GitHub.