{"record":{"id":"a7ae4c37da332e76","repo":"apache/cassandra","slug":"table-s-s-doesn-t-exist","errorCode":null,"errorMessage":"Table '%s.%s' doesn't exist","messagePattern":"Table '(.+?)\\.(.+?)' doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java","lineNumber":130,"sourceCode":"        super.validate(state);\n\n        // save the query state to use it for guardrails validation in #apply\n        this.state = state;\n    }\n\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n\n        TableMetadata table = null == keyspace\n                            ? null\n                            : keyspace.getTableOrViewNullable(tableName);\n\n        if (null == table)\n        {\n            if (!ifExists)\n                throw ire(\"Table '%s.%s' doesn't exist\", keyspaceName, tableName);\n            return schema;\n        }\n\n        if (table.params.pendingDrop)\n            throw ire(\"Cannot use ALTER TABLE on a table that is being dropped.\");\n\n        if (table.isView())\n            throw ire(\"Cannot use ALTER TABLE on a materialized view; use ALTER MATERIALIZED VIEW instead\");\n\n        return schema.withAddedOrUpdated(apply(metadata.nextEpoch(), keyspace, table, metadata));\n    }\n\n    SchemaChange schemaChangeEvent(KeyspacesDiff diff)\n    {\n        return new SchemaChange(Change.UPDATED, Target.TABLE, keyspaceName, tableName);\n    }\n\n    public void authorize(ClientState client)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java#L112-L148","documentation":"Thrown by AlterTableStatement.apply when the target table (or view) does not exist in the keyspace and IF EXISTS was not specified. Cassandra rejects the ALTER TABLE with an InvalidRequestException rather than silently succeeding.","triggerScenarios":"'ALTER TABLE keyspace.table ...' where keyspace.getTableOrViewNullable(tableName) returns null and ifExists is false; also fires when only the keyspace exists but the table name is misspelled or was already dropped","commonSituations":"Migration scripts run twice after the table was dropped in a prior run; typo in table name; case sensitivity issues (unquoted identifiers lowercased by CQL); applying DDL to the wrong cluster/environment.","solutions":["Verify the table exists: SELECT * FROM system_schema.tables WHERE keyspace_name = ?","Add IF EXISTS to make the statement idempotent: ALTER TABLE IF EXISTS ...","Fix the keyspace/table name spelling or casing"],"exampleFix":"// before\nsession.execute(\"ALTER TABLE my_app.metricss ADD description text\");\n// after\nsession.execute(\"ALTER TABLE IF EXISTS my_app.metrics ADD description text\");","handlingStrategy":"validation","validationCode":"Row r = session.execute(\"SELECT table_name FROM system_schema.tables WHERE keyspace_name=? AND table_name=?\", ks, table).one();\nif (r == null)\n    throw new IllegalStateException(\"Table \" + ks + \".\" + table + \" does not exist\");","typeGuard":null,"tryCatchPattern":"try {\n    session.execute(alter);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().endsWith(\"doesn't exist\"))\n        log.warn(\"Table missing, skipping idempotent migration: {}\", alter);\n    else throw e;\n}","preventionTips":["Use IF EXISTS for idempotent migrations","Verify environment/cluster before running DDL","Watch CQL identifier case-folding (unquoted names are lowercased)"],"tags":["cassandra","cql","ddl","table-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}