{"record":{"id":"8830bb0b40917643","repo":"iflytek/astron-agent","slug":"database-not-exist","errorCode":"DATABASE_NOT_EXIST","errorMessage":"DATABASE_NOT_EXIST","messagePattern":"DATABASE_NOT_EXIST","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":278,"sourceCode":"                lqw.isNull(DbInfo::getSpaceId);\n                lqw.eq(DbInfo::getUid, UserInfoManagerHandler.getUserId());\n            }\n            lqw.orderByDesc(DbInfo::getCreateTime);\n            page = dbInfoMapper.selectPage(page, lqw);\n            return page;\n        } catch (Exception ex) {\n            log.error(\"Failed to query database list, params={}\", JSONObject.toJSONString(databaseDto), ex);\n            throw new BusinessException(ResponseEnum.DATABASE_QUERY_FAILED);\n        }\n    }\n\n    @Transactional\n    public void createDbTable(DbTableDto dbTableDto) {\n        dataPermissionCheckTool.checkDbBelong(dbTableDto.getDbId());\n        try {\n            DbInfo dbInfo = dbInfoMapper.selectById(dbTableDto.getDbId());\n            if (dbInfo == null) {\n                throw new BusinessException(ResponseEnum.DATABASE_NOT_EXIST);\n            }\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()) {","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L260-L296","documentation":"Thrown by DatabaseService.createDbTable when dbInfoMapper.selectById(dbTableDto.getDbId()) returns null, meaning the target database does not exist (or was soft-deleted). The table creation cannot proceed without a valid parent database. Permission to the db is checked just before this, so it is a pure existence check.","triggerScenarios":"Calling createDbTable with a dbId that is not present in db_info, or one whose deleted flag is true; stale dbId from a deleted database; wrong dbId typed/serialized by the client.","commonSituations":"UI cached an old database list after the DB was deleted elsewhere; API consumer passes core-system dbId instead of the local DbInfo primary key; copy/paste of ids across environments (dev vs prod).","solutions":["Fetch the database list and confirm the dbId exists before creating tables","Re-select the target database in the UI to refresh a stale id","Verify you are using the local DbInfo id, not the core-system dbId, in the request","If soft-deleted, recreate the database first"],"exampleFix":"// before\ndbTableDto.setDbId(deletedOrUnknownId);\ndatabaseService.createDbTable(dbTableDto);\n// after\nDbInfo db = databaseService.getById(dbId);\nif (db != null) { dbTableDto.setDbId(db.getId()); databaseService.createDbTable(dbTableDto); }","handlingStrategy":"validation","validationCode":"DbInfo db = dbInfoMapper.selectById(dbId);\nif (db == null || Boolean.TRUE.equals(db.getDeleted())) { throw new IllegalStateException(\"database does not exist: \" + dbId); }","typeGuard":"boolean dbExists(DbTableDto dto) { DbInfo d = dbInfoMapper.selectById(dto.getDbId()); return d != null && !Boolean.TRUE.equals(d.getDeleted()); }","tryCatchPattern":"try { databaseService.createDbTable(dto); } catch (BusinessException e) { if (\"DATABASE_NOT_EXIST\".equals(e.getCode())) { /* refresh db list / ask user to reselect */ } else { throw e; } }","preventionTips":["Refresh cached database lists before table operations","Use the local DbInfo primary key, not the core-system dbId","Guard against cross-environment id reuse"],"tags":["not-found","database","validation","java"],"backgroundTag":"entity-not-found","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}