{"record":{"id":"f35f1baf63ad8f6c","repo":"apache/cassandra","slug":"table-s-doesn-t-exist","errorCode":null,"errorMessage":"Table '%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/CreateIndexStatement.java","lineNumber":161,"sourceCode":"\n    @Override\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        attrs.validate();\n\n        Guardrails.createSecondaryIndexesEnabled.ensureEnabled(\"Creating secondary indexes\", state);\n\n        if (attrs.isCustom && attrs.customClass.equals(SASIIndex.class.getName()) && !DatabaseDescriptor.getSASIIndexesEnabled())\n            throw new InvalidRequestException(SASI_INDEX_DISABLED);\n\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n        if (null == keyspace)\n            throw ire(KEYSPACE_DOES_NOT_EXIST, keyspaceName);\n\n        TableMetadata table = keyspace.getTableOrViewNullable(tableName);\n        if (null == table)\n            throw ire(TABLE_DOES_NOT_EXIST, tableName);\n\n        if (null != indexName && keyspace.hasIndex(indexName))\n        {\n            if (ifNotExists)\n                return schema;\n\n            throw ire(INDEX_ALREADY_EXISTS, indexName);\n        }\n\n        if (table.isCounter())\n            throw ire(COUNTER_TABLES_NOT_SUPPORTED);\n\n        if (table.isView())\n            throw ire(MATERIALIZED_VIEWS_NOT_SUPPORTED);\n\n        if (keyspace.replicationStrategy.hasTransientReplicas())\n            throw new InvalidRequestException(TRANSIENTLY_REPLICATED_KEYSPACE_NOT_SUPPORTED);\n","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateIndexStatement.java#L143-L179","documentation":"CREATE INDEX resolved the keyspace but could not find the target table or view: keyspace.getTableOrViewNullable(tableName) returned null, so the statement throws this InvalidRequestException. An index must attach to an existing table or materialized view.","triggerScenarios":"CREATE INDEX ON ks.missing_table (col); typo in table name; creating an index before the table's migration runs.","commonSituations":"Table name typos or case-sensitivity issues (unquoted names are lowercased); migration ordering (index DDL before table DDL); wrong environment missing the table.","solutions":["Correct the table name spelling and case (quote with double quotes if it contains capitals)","Create the table before the index, or fix migration ordering","Verify with DESCRIBE TABLES in the keyspace that the table exists"],"exampleFix":"// before\nCREATE INDEX ON ks.usrers(email);   -- typo\n// after\nCREATE INDEX ON ks.users(email);","handlingStrategy":"validation","validationCode":"ResultSet rs = session.execute(\"SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?\", ks, tbl);\nif (rs.all().isEmpty()) throw new IllegalStateException(\"Table does not exist: \" + ks + \".\" + tbl);","typeGuard":"boolean tableExists(Session s, String ks, String tbl) { return !s.execute(\"SELECT table_name FROM system_schema.tables WHERE keyspace_name = ? AND table_name = ?\", ks, tbl).all().isEmpty(); }","tryCatchPattern":"try { session.execute(createIndexStmt); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Table\") && e.getMessage().contains(\"doesn't exist\")) { /* fix table name or create table first */ } else throw e; }","preventionTips":["Verify table names with DESCRIBE TABLES","Unquoted identifiers are lowercased - quote case-sensitive names","Run table migrations before index migrations"],"tags":["cql","index","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"}