{"record":{"id":"f95c835b2adc0a35","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-definition-for-sequence-seqname","errorCode":null,"errorMessage":"can't find definition for sequence :{seqName}","messagePattern":"can't find definition for sequence :(.+?)","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/sequence/handler/IncrSequenceMySQLHandler.java","lineNumber":87,"sourceCode":"\t\t\tString dataNode = (String) entry.getValue();\n\t\t\tif (!seqValueMap.containsKey(seqName)) {\n\t\t\t\tseqValueMap.put(seqName, new SequenceVal(seqName, dataNode));\n\t\t\t} else {\n\t\t\t\tseqValueMap.get(seqName).dataNode = dataNode;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * save sequnce -> curval\n\t */\n\tprivate ConcurrentHashMap<String, SequenceVal> seqValueMap = new ConcurrentHashMap<String, SequenceVal>();\n\n\t@Override\n\tpublic long nextId(String seqName) {\n\t\tSequenceVal seqVal = seqValueMap.get(seqName);\n\t\tif (seqVal == null) {\n\t\t\tthrow new ConfigException(\"can't find definition for sequence :\"\n\t\t\t\t\t+ seqName);\n\t\t}\n\t\tif (!seqVal.isSuccessFetched()) {\n\t\t\t//从数据库获取\n\t\t\treturn getSeqValueFromDB(seqVal);\n\t\t} else {\n\t\t\t//已经设置 获取下一个有效id\n\t\t\treturn getNextValidSeqVal(seqVal);\n\t\t}\n\n\t}\n\t//获取有效的sequence\n\tprivate Long getNextValidSeqVal(SequenceVal seqVal) {\n\t\tLong nexVal = seqVal.nextValue();\n\t\t//当前id有效返回 无效则从数据库获取\n\t\tif (seqVal.isNexValValid(nexVal)) {\n\t\t\treturn nexVal;\n\t\t} else {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/sequence/handler/IncrSequenceMySQLHandler.java#L69-L105","documentation":"IncrSequenceMySQLHandler.nextId looks up the requested sequence name in its in-memory seqValueMap, which is populated at startup from the configured DB sequence definitions (sequence table in a schema, per sequence_db_conf). If the name is absent, it throws ConfigException — this is a configuration-time lookup failure, not a runtime fetch failure. MyCat refuses to generate IDs for sequences it has no definition for.","triggerScenarios":"Calling nextId(seqName) with a sequence name that has no row in the sequence table referenced by sequence_db_conf (or the schema is not mapped for that sequence), so seqValueMap.get(seqName) returns null.","commonSituations":"Typo in the sequence/table name in SQL (e.g. using NEXT VALUE FOR mytable where mytable has no sequence row); missing row in the MYCAT_SEQUENCE table; sequence_db_conf pointing at the wrong schema; sequence added to app code before being added to MyCat config.","solutions":["Add a row for the sequence name in the sequence table (e.g. MYCAT_SEQUENCE) of the schema referenced by sequence_db_conf and restart/reload MyCat.","Check that sequence_db_conf maps the sequence's target schema correctly and that the name matches exactly (case-sensitive) the one used in nextId/SQL.","Verify the name used in the application/SQL matches the defined sequence; fix typos.","After config changes, restart MyCat or trigger config reload so seqValueMap is repopulated."],"exampleFix":"// before\n// SELECT next value for MYCATSEQ_AUDIT  -> ConfigException: can't find definition for sequence :AUDIT\n// after\n-- insert the missing definition, then retry\nINSERT INTO MYCAT_SEQUENCE(name, current_value, increment)\nVALUES ('AUDIT', 100000, 100);","handlingStrategy":"validation","validationCode":"public static void requireSequenceDefined(Map<String, ?> seqValueMap, String seqName) {\n    if (!seqValueMap.containsKey(seqName)) {\n        throw new ConfigException(\"can't find definition for sequence :\" + seqName\n            + \" — add a row to the sequence table and map it in sequence_db_conf\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    long id = handler.nextId(seqName);\n} catch (ConfigException e) {\n    log.error(\"Sequence {} not defined; check sequence table + sequence_db_conf\", seqName, e);\n    throw new MissingSequenceConfigException(e);\n}","preventionTips":["Add a startup self-check that every table using NEXT VALUE has a matching sequence row.","Keep sequence definitions (sequence table rows + sequence_db_conf schema mapping) in version-controlled SQL migrations.","Match sequence names exactly (mind case sensitivity) between app SQL and MyCat config.","Restart or reload MyCat config after adding new sequence definitions."],"tags":["sequence","config-error","missing-definition","mycat"],"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-16T04:17:20.429Z"}