apache/cassandra · error · InvalidRequestException
Type . doesn't exist
Error message
Type %s.%s doesn't exist
What it means
Thrown by ALTER TYPE when the user-defined type being altered does not exist in the keyspace. Without `IF EXISTS`, the statement fails rather than silently doing nothing; with `IF EXISTS`, the alteration is a no-op. This guards schema statements against referencing nonexistent type definitions.
Solutions
- Verify the type exists with `DESCRIBE KEYSPACE ks;` or a system_schema.types query and correct the name
- Add `IF EXISTS` (`ALTER TYPE ks.typ ADD ... IF EXISTS`) if a no-op is acceptable when the type is absent
- Ensure the migration that creates the type runs before the one that alters it
Example fix
// before ALTER TYPE ks.address ADD zip text; // after ALTER TYPE ks.address ADD zip text IF EXISTS;
Defensive patterns
Strategy: validation
Validate before calling
boolean typeExists = session.execute("SELECT type_name FROM system_schema.types WHERE keyspace_name=? AND type_name=?", ks, typeName).iterator().hasNext();
if (!typeExists) throw new IllegalStateException("Type " + ks + "." + typeName + " does not exist"); Type guard
boolean userTypeExists(Session s, String ks, String typeName) {
return s.execute("SELECT type_name FROM system_schema.types WHERE keyspace_name=? AND type_name=?", ks, typeName).iterator().hasNext();
} Try / catch
try { session.execute(alterTypeStmt); }
catch (InvalidQueryException e) {
if (e.getMessage().startsWith("Type ") && e.getMessage().endsWith("doesn't exist")) {
// create the type or skip
} else throw e;
} Prevention
- Verify the type in system_schema.types before altering
- Use IF EXISTS for optional alterations
- Order migrations so CREATE TYPE precedes ALTER TYPE
- Fully qualify the keyspace to avoid wrong-keyspace lookups
When it happens
Trigger: Executing `ALTER TYPE ks.typ ADD field type` (or any ALTER TYPE variant) where `keyspace.types.getNullable(bytes(typeName))` returns null, i.e. no UDT of that name exists in the keyspace, and the statement lacks `IF EXISTS`.
Common situations: Typo in the type name or keyspace; running a migration before the CREATE TYPE statement; dropping the type in an earlier migration and then trying to alter it; connecting to a cluster where the type was never created.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Cannot add new field
- Cannot add new field
- Cannot drop non-frozen column
- Invalid field deletion operation for non-UDT column
- Non-frozen UDTs are not allowed inside collections:
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/967afa22a4c6ca8c.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/AlterTypeStatement.java:89
SchemaChange schemaChangeEvent(Keyspaces.KeyspacesDiff diff)
{
return new SchemaChange(Change.UPDATED, Target.TYPE, keyspaceName, typeName);
}
@Override
public Keyspaces apply(ClusterMetadata metadata)
{
Keyspaces schema = metadata.schema.getKeyspaces();
KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
UserType type = null == keyspace
? null
: keyspace.types.getNullable(bytes(typeName));
if (null == type)
{
if (!ifExists)
throw ire("Type %s.%s doesn't exist", keyspaceName, typeName);
return schema;
}
return schema.withAddedOrUpdated(keyspace.withUpdatedUserType(apply(keyspace, type)));
}
abstract UserType apply(KeyspaceMetadata keyspace, UserType type);
@Override
public AuditLogContext getAuditLogContext()
{
return new AuditLogContext(AuditLogEntryType.ALTER_TYPE, keyspaceName, typeName);
}
public String toString()
{
return String.format("%s (%s, %s)", getClass().getSimpleName(), keyspaceName, typeName);
}View on GitHub (pinned to 88fd0f6a0e)