{"record":{"id":"66802209947d9336","repo":"elunez/eladmin","slug":"error-668022","errorCode":null,"errorMessage":"请先配置生成器","messagePattern":"请先配置生成器","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-generator/src/main/java/me/zhengjie/service/impl/GeneratorServiceImpl.java","lineNumber":172,"sourceCode":"        for (ColumnInfo columnInfo : columnInfos) {\n            // 根据字段名称查找\n            List<ColumnInfo> columns = columnInfoList.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList());\n            // 如果找不到，就代表字段被删除了，则需要删除该字段\n            if (CollectionUtil.isEmpty(columns)) {\n                columnInfoRepository.delete(columnInfo);\n            }\n        }\n    }\n\n    @Override\n    public void save(List<ColumnInfo> columnInfos) {\n        columnInfoRepository.saveAll(columnInfos);\n    }\n\n    @Override\n    public void generator(GenConfig genConfig, List<ColumnInfo> columns) {\n        if (genConfig.getId() == null) {\n            throw new BadRequestException(CONFIG_MESSAGE);\n        }\n        try {\n            GenUtil.generatorCode(columns, genConfig);\n        } catch (IOException e) {\n            log.error(e.getMessage(), e);\n            throw new BadRequestException(\"生成失败，请手动处理已生成的文件\");\n        }\n    }\n\n    @Override\n    public ResponseEntity<Object> preview(GenConfig genConfig, List<ColumnInfo> columns) {\n        if (genConfig.getId() == null) {\n            throw new BadRequestException(CONFIG_MESSAGE);\n        }\n        List<Map<String, Object>> genList = GenUtil.preview(columns, genConfig);\n        return new ResponseEntity<>(genList, HttpStatus.OK);\n    }\n","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-generator/src/main/java/me/zhengjie/service/impl/GeneratorServiceImpl.java#L154-L190","documentation":"GeneratorServiceImpl.generator throws BadRequestException(CONFIG_MESSAGE = '请先配置生成器') when the GenConfig row for the table has a null id, meaning no generator configuration has been saved for that table yet. The config (package name, author, prefix, path) must exist before files can be generated.","triggerScenarios":"POST /api/generator/{tableName}/0 for a table whose gen_config record has not been created/saved (e.g. a newly synced table, or the config was deleted from the generator config screen).","commonSituations":"Fresh installations where the '代码生成' config tab was never filled; deleting the GenConfig row then clicking generate; multi-module setups where the config exists for another table but not the requested one.","solutions":["Open the generator config page, fill in package/authors/API path for that table and save (PUT /api/genConfig), then retry.","Verify via GET /api/genConfig/{tableName} that a config with a non-null id is returned before generating.","If configs were wiped, re-enter them — check the gen_config table has a row matching the table name."],"exampleFix":"// before: generate immediately after syncing columns\ngeneratorService.generator(genConfigService.find(tableName), columns); // id == null -> 400\n\n// after: persist config first, then generate\nGenConfig config = genConfigService.find(tableName);\nconfig.setPackName(\"me.zhengjie.mine\");\ngenConfigService.update(config.getName(), config);   // now has id\ngeneratorService.generator(config, columns);","handlingStrategy":"validation","validationCode":"// Call the config endpoint first; save if missing\nGenConfig config = genConfigService.find(tableName);\nif (config == null || config.getId() == null) {\n    config = defaultConfigFor(tableName);\n    genConfigService.update(config.getTableName(), config); // persists, assigns id\n}\ngeneratorService.generator(config, columns);","typeGuard":"private boolean isConfigured(GenConfig c) {\n    return c != null && c.getId() != null\n        && StringUtils.isNotBlank(c.getPackName())\n        && StringUtils.isNotBlank(c.getPath());\n}","tryCatchPattern":"try {\n    generatorService.generator(config, columns);\n} catch (BadRequestException e) {\n    if (\"请先配置生成器\".equals(e.getMessage())) { openConfigTab(tableName); return; }\n    throw e;\n}","preventionTips":["Always configure (and save) the generator config for a table before generating — the UI enforces it, APIs don't.","Script the 'ensure config exists' step before batch generation.","Treat an empty gen_config table as a setup smell on fresh installs."],"tags":["code-generator","configuration","eladmin","precondition"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}