{"record":{"id":"2a94638a362191e7","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-table-define-in-schema-schema","errorCode":null,"errorMessage":"can't find table define in schema  schema:","messagePattern":"can't find table define in schema  schema:","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 target table in the loaded schema configuration (schema.getTables()). If the table name from the INSERT is not defined in Mycat's schema.xml, no TableConfig exists and routing cannot proceed, so a SQLNonTransientException is thrown naming the table and schema. Mycat only routes tables it knows about.","triggerScenarios":"INSERT against a table absent from schema.xml (no <table> entry in the referenced schema); table name case mismatch after uppercasing (Mycat compares upper-cased names); using a schema name different from the configured one.","commonSituations":"Table created on MySQL backends but not declared in schema.xml; hot reload not performed after editing schema.xml; lowercase vs uppercase table-name mismatch in config; inserting into an unconfigured global/child table.","solutions":["Add a <table> entry for the table in schema.xml under the correct schema, with dataNode/rule attributes.","Reload Mycat configuration (server restart or reload @@config) so the new table definition is picked up.","Match the case of the table in the INSERT to the schema.xml definition (Mycat compares uppercase names)."],"exampleFix":"// before (schema.xml)\n<schema name=\"TESTDB\">\n  <table name=\"orders\" dataNode=\"dn1\" rule=\"rule1\"/>\n</schema>\n// after — add the missing table\n<schema name=\"TESTDB\">\n  <table name=\"orders\" dataNode=\"dn1\" rule=\"rule1\"/>\n  <table name=\"order_items\" dataNode=\"dn1,dn2\" rule=\"rule1\"/>\n</schema>","handlingStrategy":"try-catch","validationCode":"// Pre-check the table is configured before issuing the INSERT\nString table = \"ORDER_ITEMS\"; // upper-cased table name\n// after load: Map<String, TableConfig> tables = schema.getTables();\nif (!tables.containsKey(table)) {\n  throw new IllegalStateException(\"Table not declared in Mycat schema.xml: \" + table);\n}","typeGuard":null,"tryCatchPattern":"try {\n  stmt.execute(insertSql);\n} catch (SQLNonTransientException e) {\n  if (e.getMessage().startsWith(\"can't find table define in schema\")) {\n    // fix schema.xml and reload config, then retry\n  } else { throw e; }\n}","preventionTips":["Keep schema.xml table entries in sync with backend MySQL schema; reload config after edits.","Use consistent uppercase table names in SQL and config."],"tags":["schema-config","insert-routing","table-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}