apache/cassandra · error · InvalidRequestException
Materialized view '%s.%s' doesn't exist
Error message
Materialized view '%s.%s' doesn't exist
What it means
ALTER VIEW ... / ALTER MATERIALIZED VIEW ... was issued for a materialized view that does not exist in the given keyspace. AlterViewStatement.apply() looks up the view in KeyspaceMetadata.views and, when absent and no IF EXISTS clause was given, throws this InvalidRequestException. It is a schema-not-found guard before validating and applying the new view params.
Source
Thrown at src/java/org/apache/cassandra/cql3/statements/schema/AlterViewStatement.java:82
public boolean compatibleWith(ClusterMetadata metadata)
{
return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);
}
@Override
public Keyspaces apply(ClusterMetadata metadata)
{
Keyspaces schema = metadata.schema.getKeyspaces();
KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
ViewMetadata view = null == keyspace
? null
: keyspace.views.getNullable(viewName);
if (null == view)
{
if (ifExists) return schema;
throw ire("Materialized view '%s.%s' doesn't exist", keyspaceName, viewName);
}
attrs.validate();
// Guardrails on table properties
Guardrails.tableProperties.guard(attrs.updatedProperties(), attrs::removeProperty, state);
TableParams params = attrs.asAlteredTableParams(view.metadata.params);
if (params.gcGraceSeconds == 0)
{
throw ire("Cannot alter gc_grace_seconds of a materialized view to 0, since this " +
"value is used to TTL undelivered updates. Setting gc_grace_seconds too " +
"low might cause undelivered updates to expire before being replayed.");
}
if (params.defaultTimeToLive > 0)
{View on GitHub (pinned to 88fd0f6a0e)
Solutions
- Verify the view exists with `DESCRIBE MATERIALIZED VIEWS` or query system_schema.views
- Correct the keyspace/view name in the statement
- Add `IF EXISTS` if the alteration should be a no-op when the view is missing
- Re-create the view if it was dropped unintentionally
Example fix
// before ALTER MATERIALIZED VIEW ks.user_by_email WITH gc_grace_seconds = 86400; // after (verify first, or tolerate absence) ALTER MATERIALIZED VIEW ks."user_by_email" WITH gc_grace_seconds = 86400; -- or ALTER MATERIALIZED VIEW ks.user_by_email IF EXISTS WITH gc_grace_seconds = 86400;
Defensive patterns
Strategy: validation
Validate before calling
// Verify the view exists before altering
const row = await session.execute(
"SELECT view_name FROM system_schema.views WHERE keyspace_name = ? AND view_name = ?",
[keyspace, viewName]);
if (row.rows.length === 0 && !ifExists) throw new Error(`View ${keyspace}.${viewName} not found`); Type guard
null
Try / catch
try {
session.execute("ALTER MATERIALIZED VIEW ks.v WITH gc_grace_seconds = 86400");
} catch (e) {
if (/doesn't exist/.test(e.message) && /view/i.test(e.message)) {
logger.warn(`view ks.v missing, skipping alteration`);
} else throw e;
} Prevention
- Look up system_schema.views before altering
- Quote mixed-case identifiers consistently
- Run existence checks in the same environment as the alteration
- Use IF EXISTS for idempotent migrations
When it happens
Trigger: `ALTER MATERIALIZED VIEW <ks>.<view> WITH ...` where the view name is misspelled, the view was dropped, it lives in a different keyspace, or USE-keyspace resolution differs; throws unless IF EXISTS was specified.
Common situations: Typos in view names in migration scripts; altering a view after it was dropped by another process; assuming views live in a different keyspace than the base table; environment drift between dev/prod schemas.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Load CIDR groups cache operation not supported by %s
- 'Get CIDR groups for IP' operation not supported by %s
- ACCESS TO DATACENTERS operations not supported by AllowAllNe
- Remote configuration of auth caches is disabled
- Keyspace %s doesn't exist
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/eaf118b575d4db77.
Report an issue: GitHub.