testcontainers/testcontainers-java · error · UnsupportedOperationException
The TiDB docker image does not currently support this
Error message
The TiDB docker image does not currently support this
What it means
TiDBContainer overrides withDatabaseName purely to reject it: the TiDB docker image's default startup scripts do not support creating a custom initial database, so this unsupported operation is thrown immediately instead of failing later in container startup.
Solutions
- Remove the withDatabaseName call and use the default database name returned by getDatabaseName().
- Create your database with a plain JDBC statement after the container starts: execute 'CREATE DATABASE mydb' via the container's DataSource/JDBC URL.
- If database-name customization is essential, keep using MySQLContainer (TiDB is wire-compatible).
Example fix
// before
new TiDBContainer("pingcap/tidb:v7.5.0").withDatabaseName("appdb").start();
// after
TiDBContainer c = new TiDBContainer("pingcap/tidb:v7.5.0");
c.start();
try (Connection cn = DriverManager.getConnection(c.getJdbcUrl(), c.getUsername(), c.getPassword())) {
cn.createStatement().execute("CREATE DATABASE appdb");
} Defensive patterns
Strategy: validation
Validate before calling
if (container instanceof TiDBContainer && wantsCustomDatabase) {
throw new IllegalStateException("TiDBContainer does not support withDatabaseName; create the database via SQL after start");
} Try / catch
try { container.withDatabaseName("appdb"); } catch (UnsupportedOperationException e) { /* use default database or create via JDBC post-start */ } Prevention
- Do not route TiDB containers through generic JDBC-container builders that set database name.
- Create extra databases with CREATE DATABASE after start().
When it happens
Trigger: Calling withDatabaseName("mydb") on a TiDBContainer before start().
Common situations: Shared JDBC URL builder code that calls withDatabaseName on every JDBCContainer; switching a test from MySQLContainer to TiDBContainer without removing database-name customization.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Error while executing init script
- getParentLogger not supported
- Setting a in not supported in the versions below 22.1.0
- The ClickHouse does not support this
- The Oracle Database driver does not support this
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/1ee424199b861610.
Report an issue: GitHub.
Appendix: source
Thrown at modules/tidb/src/main/java/org/testcontainers/tidb/TiDBContainer.java:124
@Override
public String getUsername() {
return username;
}
@Override
public String getPassword() {
return password;
}
@Override
public String getTestQueryString() {
return "SELECT 1";
}
@Override
public TiDBContainer withDatabaseName(final String databaseName) {
throw new UnsupportedOperationException("The TiDB docker image does not currently support this");
}
@Override
public TiDBContainer withUsername(final String username) {
throw new UnsupportedOperationException("The TiDB docker image does not currently support this");
}
@Override
public TiDBContainer withPassword(final String password) {
throw new UnsupportedOperationException("The TiDB docker image does not currently support this");
}
}
View on GitHub (pinned to 8e549514e3)