{"record":{"id":"281afe7fd66e6c9b","repo":"MyCATApache/Mycat-Server","slug":"op-table-not-in-schema-tablename","errorCode":null,"errorMessage":"op table not in schema----{tablename}","messagePattern":"op table not in schema----(.+?)","errorType":"exception","errorClass":"SQLSyntaxErrorException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/RouterUtil.java","lineNumber":258,"sourceCode":"\t\t\t\t\t}  else if(isSlotFunction){\r\n\t\t\t\t\t\tnodes[i].setSlot(-1);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnodes[i].setStatement(rrsStmt);\r\n\t\t\t\t}\r\n\t\t\t\trrs.setNodes(nodes);\r\n\t\t\t}\r\n\t\t\trrs.setStatement(rrsStmt);\r\n\t\t\treturn rrs;\r\n\t\t}else if(schema.getDataNode()!=null){\t\t//默认节点ddl\r\n\t\t\tRouteResultsetNode[] nodes = new RouteResultsetNode[1];\r\n\t\t\tnodes[0] = new RouteResultsetNode(schema.getDataNode(), sqlType, stmt);\r\n\t\t\tnodes[0].setSource(rrs);\r\n\t\t\trrs.setNodes(nodes);\r\n\t\t\treturn rrs;\r\n\t\t}\r\n\t\t//both tablename and defaultnode null\r\n\t\tLOGGER.error(\"table not in schema----\"+tablename);\r\n\t\tthrow new SQLSyntaxErrorException(\"op table not in schema----\"+tablename);\r\n\t}\r\n\r\n\tprivate  static String changeCreateTable(SchemaConfig schema,String tableName,String sql) {\r\n\t\tif (schema.getTables().containsKey(tableName)) {\r\n\t\t\tMySqlStatementParser parser = new MySqlStatementParser(sql);\r\n\t\t\tSQLStatement insertStatement = parser.parseStatement();\r\n\t\t\tif (insertStatement instanceof MySqlCreateTableStatement) {\r\n\t\t\t\tTableConfig tableConfig = schema.getTables().get(tableName);\r\n\t\t\t\tAbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();\r\n\t\t\t\tif (algorithm instanceof SlotFunction) {\r\n\t\t\t\t\tSQLColumnDefinition column = new SQLColumnDefinition();\r\n\t\t\t\t\tcolumn.setDataType(new SQLCharacterDataType(\"int\"));\r\n\t\t\t\t\tcolumn.setName(new SQLIdentifierExpr(\"_slot\"));\r\n\t\t\t\t\tcolumn.setComment(new SQLCharExpr(\"自动迁移算法slot,禁止修改\"));\r\n\t\t\t\t\t((SQLCreateTableStatement) insertStatement).getTableElementList().add(column);\r\n\t\t\t\t\treturn insertStatement.toString();\r\n\r\n\t\t\t\t}\r","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/RouterUtil.java#L240-L276","documentation":"routeToDDLNode cannot resolve the table named in the SQL to any schema/table configuration, so it cannot determine a target data node. MyCat logs 'table not in schema' and throws SQLSyntaxErrorException to reject statements against tables absent from schema.xml. This keeps routing from silently sending DML/DDL to a wrong or empty node set.","triggerScenarios":"Executing any SQL statement (via routeToDDLNode / routeNormalSqlWithDDLNode path) whose table name has no entry in schemaConfig.getTables() and where the schema has no default dataNode; also calling RouterUtil.routeToDDLNode directly with an unknown tableName.","commonSituations":"Typo in table name in the SQL; table exists in the database but was never declared as a <table> in schema.xml; client connects to the wrong logical schema; table name case mismatch between SQL and config.","solutions":["Add the missing table to schema.xml as a <table name=\"...\" dataNode=\"...\"/> entry and restart/reload MyCat config","Set a default dataNode on the <schema> element so unconfigured tables route to a single node","Correct the table name in the SQL or ensure the client connects to the intended schema"],"exampleFix":"// before (schema.xml)\n<schema name=\"db\" checkSQLschema=\"true\">\n  <table name=\"t_user\" dataNode=\"dn1\"/>\n</schema>\n// after\n<schema name=\"db\" checkSQLschema=\"true\">\n  <table name=\"t_user\" dataNode=\"dn1\"/>\n  <table name=\"t_order\" dataNode=\"dn1,dn2\"/>\n</schema>","handlingStrategy":"validation","validationCode":"// before executing SQL\nif (!schemaConfig.getTables().containsKey(tableName) && schemaConfig.getDataNode() == null) {\n  throw new IllegalStateException(\"table \" + tableName + \" is not declared in schema.xml\");\n}","typeGuard":null,"tryCatchPattern":"try { RouterUtil.routeToDDLNode(...); } catch (SQLSyntaxErrorException e) { // table missing in schema config\n  LOGGER.error(\"configure the table in schema.xml\", e); }","preventionTips":["Keep schema.xml in sync with actual DB tables","Use config validation tooling on deploy","Watch for table-name typos and case mismatches"],"tags":["sql","routing","config"],"backgroundTag":"entity-not-found","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}