{"record":{"id":"a013753be2c9923d","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-table-define-in-schema-tablename","errorCode":null,"errorMessage":"\"can't find table define in schema \" + tableName + \" schema:\" + schema.getName()","messagePattern":"\"can't find table define in schema \" \\+ tableName \\+ \" schema:\" \\+ schema\\.getName\\(\\)","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java","lineNumber":64,"sourceCode":"\t */\n\t@Override\n\tpublic void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) throws SQLNonTransientException {\n\t\tMySqlInsertStatement insert = (MySqlInsertStatement)stmt;\n\t\tString tableName = StringUtil.removeBackquote(insert.getTableName().getSimpleName()).toUpperCase();\n\n\t\tctx.addTable(tableName);\n\t\tif(RouterUtil.isNoSharding(schema,tableName)) {//整个schema都不分库或者该表不拆分\n\t\t\tRouterUtil.routeForTableMeta(rrs, schema, tableName, rrs.getStatement());\n\t\t\trrs.setFinishedRoute(true);\n\t\t\treturn;\n\t\t}\n\n\t\tTableConfig tc = schema.getTables().get(tableName);\n\t\tif(tc == null) {\n\t\t\tString msg = \"can't find table define in schema \"\n\t\t\t\t\t+ tableName + \" schema:\" + schema.getName();\n\t\t\tLOGGER.warn(msg);\n\t\t\tthrow new SQLNonTransientException(msg);\n\t\t} else {\n\t\t\t//childTable的insert直接在解析过程中完成路由\n\t\t\tif (tc.isChildTable()) {\n\t\t\t\tparserChildTable(schema, rrs, tableName, insert);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tString partitionColumn = tc.getPartitionColumn();\n\t\t\t\n\t\t\tif(partitionColumn != null) {//分片表\n\t\t\t\t//拆分表必须给出column list,否则无法寻找分片字段的值\n\t\t\t\tif(insert.getColumns() == null || insert.getColumns().size() == 0) {\n\t\t\t\t\tthrow new SQLSyntaxErrorException(\"partition table, insert must provide ColumnList\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//批量insert\n\t\t\t\tif(isMultiInsert(insert)) {\n//\t\t\t\t\tString msg = \"multi insert not provided\" ;","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java#L46-L82","documentation":"The insert parser looks up the table name from the INSERT statement in the schema configuration (schema.xml tables map). If no TableConfig exists for that table, Mycat cannot determine datanodes/sharding rules, so it throws SQLNonTransientException.","triggerScenarios":"Executing INSERT INTO <tbl> ... where <tbl> (uppercased, backquotes stripped) is absent from schema.getTables(); typically the table is not declared in schema.xml or the wrong logical schema is targeted by the connection.","commonSituations":"Table added to backend MySQL but not to schema.xml; connecting to the wrong Mycat schema; case-sensitivity mismatch between SQL table name and schema.xml table declaration; typo in table name.","solutions":["Add a <table> entry for the table in schema.xml (with its datanodes and rule) and reload/restart Mycat","Verify the client connected to the intended schema (schema name in the message)","Check the table name spelling and case matches schema.xml exactly (names are uppercased before lookup)","If the table lives only on one node, ensure it is still declared in schema.xml, or route it via a schema entry with no rule"],"exampleFix":"// before (schema.xml)\n<schema name=\"db\">\n  <table name=\"t1\" dataNode=\"dn1\"/>\n</schema>\n// after\n<schema name=\"db\">\n  <table name=\"t1\" dataNode=\"dn1\"/>\n  <table name=\"t2\" dataNode=\"dn1,dn2\" rule=\"rule1\"/>\n</schema>","handlingStrategy":"validation","validationCode":"// verify table is declared before inserting\nSchemaConfig schema = MycatServer.getInstance().getConfig().getSchemas().get(currentSchema);\nString table = sqlTableName.toUpperCase();\nif (schema == null || !schema.getTables().containsKey(table)) {\n    throw new IllegalStateException(\"Table not defined in schema.xml: \" + table);\n}","typeGuard":"static TableConfig requireTable(SchemaConfig schema, String tableName) {\n    TableConfig tc = schema.getTables().get(tableName);\n    if (tc == null) throw new IllegalStateException(\"can't find table define in schema \" + tableName);\n    return tc;\n}","tryCatchPattern":"try {\n    routeResult = route(insertSql);\n} catch (SQLNonTransientException e) {\n    if (e.getMessage().startsWith(\"can't find table define in schema\")) {\n        throw new ConfigurationException(\"Declare the table in schema.xml or connect to the correct schema\", e);\n    }\n    throw e;\n}","preventionTips":["Keep schema.xml in sync with backend DDL; add every routable table","Verify the JDBC URL targets the intended Mycat schema","Normalize table-name case to match schema.xml declarations","Run a startup checklist that SELECTs each expected table through Mycat"],"tags":["sql","mycat","schema","configuration"],"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"}