{"record":{"id":"82f4c62482fc5a1c","repo":"iflytek/astron-agent","slug":"database-table-field-cannot-empty","errorCode":"DATABASE_TABLE_FIELD_CANNOT_EMPTY","errorMessage":"DATABASE_TABLE_FIELD_CANNOT_EMPTY","messagePattern":"DATABASE_TABLE_FIELD_CANNOT_EMPTY","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java","lineNumber":297,"sourceCode":"            }\n            // Table count limit\n            Long tableCount = dbTableMapper.selectCount(new QueryWrapper<DbTable>().lambda()\n                    .eq(DbTable::getDbId, dbInfo.getDbId())\n                    .eq(DbTable::getDeleted, false));\n            if (tableCount > 20) {\n                throw new BusinessException(ResponseEnum.DATABASE_COUNT_LIMITED);\n            }\n            // Duplicate table name validation\n            Long count = dbTableMapper.selectCount(new QueryWrapper<DbTable>().lambda()\n                    .eq(DbTable::getName, dbTableDto.getName())\n                    .eq(DbTable::getDbId, dbInfo.getDbId())\n                    .eq(DbTable::getDeleted, false));\n            if (count > 0) {\n                throw new BusinessException(ResponseEnum.DATABASE_TABLE_NAME_EXIST);\n            }\n            // Build DDL statement and validate required system fields\n            if (dbTableDto.getFields() == null || dbTableDto.getFields().isEmpty()) {\n                throw new BusinessException(ResponseEnum.DATABASE_TABLE_FIELD_CANNOT_EMPTY);\n            }\n            // Table fields cannot exceed 20\n            if (dbTableDto.getFields().size() > 20) {\n                throw new BusinessException(ResponseEnum.DATABASE_FIELD_CANNOT_BEYOND_20);\n            }\n            // Save information\n            DbTable dbTable = new DbTable();\n            BeanUtils.copyProperties(dbTableDto, dbTable);\n            dbTable.setCreateTime(new Date());\n            dbTable.setUpdateTime(new Date());\n            dbTableMapper.insert(dbTable);\n            List<String> systemFields = Arrays.asList(SYSTEM_FIELDS);\n            List<DbTableField> fields = new ArrayList<>();\n            for (DbTableFieldDto field : dbTableDto.getFields()) {\n                DbTableField dbTableField = new DbTableField();\n                BeanUtils.copyProperties(field, dbTableField);\n                if (systemFields.contains(field.getName())) {\n                    dbTableField.setIsSystem(true);","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L279-L315","documentation":"Thrown by DatabaseService.createDbTable when the DbTableDto submitted for table creation has a null or empty fields list. The platform requires at least one user-defined column to build the DDL for the physical table; a table with no fields cannot be materialized in the core database system.","triggerScenarios":"Calling POST table creation (createDbTable) with a request body where 'fields' is absent, null, or an empty array []. Note the outer catch (Exception) at line 336 wraps any exception into DATABASE_TABLE_CREATE_FAILED, but this specific check at line 296-297 throws DATABASE_TABLE_FIELD_CANNOT_EMPTY before DDL execution.","commonSituations":"Frontend form submitted without adding any columns; API consumers scripting table creation omit the fields array; a DTO deserialization drops fields because the JSON key is misspelled (e.g. 'field' instead of 'fields').","solutions":["Add at least one field object to the 'fields' array in the create-table request payload","If calling via UI, add columns in the table creation form before submitting","Verify the JSON key is exactly 'fields' and is a non-empty array in the request body"],"exampleFix":"// before\nPOST /database/table\n{\"dbId\": 1, \"name\": \"users\", \"fields\": []}\n// after\nPOST /database/table\n{\"dbId\": 1, \"name\": \"users\", \"fields\": [{\"name\": \"username\", \"type\": \"VARCHAR\"}]}","handlingStrategy":"validation","validationCode":"if (dto.getFields() == null || dto.getFields().isEmpty()) {\n    throw new IllegalArgumentException(\"fields must contain at least one column\");\n}","typeGuard":"boolean hasFields(DbTableDto dto) {\n    return dto.getFields() != null && !dto.getFields().isEmpty();\n}","tryCatchPattern":"try {\n    databaseService.createDbTable(dto);\n} catch (BusinessException e) {\n    if (\"DATABASE_TABLE_FIELD_CANNOT_EMPTY\".equals(e.getCode())) { /* prompt user to add fields */ }\n    throw e;\n}","preventionTips":["Validate the fields array client-side before submitting the create-table form","Use a request-schema validator (e.g. @NotEmpty on the DTO list) for early rejection","Check API payload key spelling ('fields') when scripting requests"],"tags":["validation","database","empty-fields"],"backgroundTag":"empty-required-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}