{"record":{"id":"bc7e1bcd1528ba46","repo":"MyCATApache/Mycat-Server","slug":"name-in-nosharding-mode-schema-must-have-defaul","errorCode":null,"errorMessage":"${name} in noSharding mode schema must have default dataNode ","messagePattern":"(.+?) in noSharding mode schema must have default dataNode ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/main/java/io/mycat/config/model/SchemaConfig.java","lineNumber":73,"sourceCode":"\t * ,then A is root table\n\t */\n\tprivate final Map<String, TableConfig> joinRel2TableMap = new HashMap<String, TableConfig>();\n\tprivate final String[] allDataNodeStrArr;\n\n\tprivate  Map<String,String> dataNodeDbTypeMap=new HashMap<>();\n\n\tpublic SchemaConfig(String name, String dataNode,\n\t\t\tMap<String, TableConfig> tables, int defaultMaxLimit,\n\t\t\tboolean checkSQLschema,String randomDataNode) {\n\t\tthis.name = name;\n\t\tthis.dataNode = dataNode;\n\t\tthis.checkSQLSchema = checkSQLschema;\n\t\tthis.tables = tables;\n\t\tthis.defaultMaxLimit = defaultMaxLimit;\n\t\tbuildJoinMap(tables);\n\t\tthis.noSharding = (tables == null || tables.isEmpty());\n\t\tif (noSharding && dataNode == null) {\n\t\t\tthrow new RuntimeException(name\n\t\t\t\t\t+ \" in noSharding mode schema must have default dataNode \");\n\t\t}\n\t\tthis.metaDataNodes = buildMetaDataNodes();\n\t\tthis.allDataNodes = buildAllDataNodes();\n//\t\tthis.metaDataNodes = buildAllDataNodes();\n\t\tif (this.allDataNodes != null && !this.allDataNodes.isEmpty()) {\n\t\t\tString[] dnArr = new String[this.allDataNodes.size()];\n\t\t\tdnArr = this.allDataNodes.toArray(dnArr);\n\t\t\tthis.allDataNodeStrArr = dnArr;\n\t\t} else {\n\t\t\tthis.allDataNodeStrArr = null;\n\t\t}\n\t\tthis.randomDataNode =randomDataNode;\n\t}\n\n\tpublic String getDefaultDataNodeDbType()\n\t{\n\t\treturn defaultDataNodeDbType;","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/model/SchemaConfig.java#L55-L91","documentation":"SchemaConfig's constructor determines a schema is in noSharding mode when it has no <table> entries; in that mode the schema itself must carry a default dataNode. If tables is null/empty and dataNode is null, a RuntimeException is thrown because Mycat would have nowhere to route queries for the schema.","triggerScenarios":"Constructing a SchemaConfig (via schema.xml parsing) where the schema has no child table elements and no dataNode attribute is set.","commonSituations":"Defining a schema element with an empty or absent table list and forgetting dataNode=\"dn1\"; migrating a schema from sharded to no-sharding mode and dropping the dataNode attribute.","solutions":["Add dataNode=\"<existing-dataNode-name>\" to the <schema> element in schema.xml.","Add at least one <table> mapping to the schema so it is no longer noSharding mode."],"exampleFix":"// before (schema.xml)\n<schema name=\"TESTDB\" checkSQLschema=\"true\"></schema>\n// after\n<schema name=\"TESTDB\" checkSQLschema=\"true\" dataNode=\"dn1\"></schema>","handlingStrategy":"validation","validationCode":"// XML/config check before loading\nboolean hasTables = schemaTables != null && !schemaTables.isEmpty();\nif (!hasTables && (schemaDataNode == null || schemaDataNode.isEmpty())) {\n    throw new IllegalArgumentException(\"noSharding schema requires dataNode attribute\");\n}","typeGuard":null,"tryCatchPattern":"try { new SchemaConfig(...); } catch (RuntimeException e) { if (e.getMessage().contains(\"must have default dataNode\")) { LOG.error(\"Schema {} needs dataNode attribute\", name); } throw e; }","preventionTips":["Always set dataNode on schemas that contain no table elements.","Template your schema.xml with a required dataNode placeholder.","Run schema.xml validation in CI before deploying Mycat."],"tags":["config","mycat","schema","sharding"],"backgroundTag":"missing-required-config-field","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"}