{"record":{"id":"919b8db558a04fbf","repo":"iflytek/astron-agent","slug":"database-table-name-exist","errorCode":"DATABASE_TABLE_NAME_EXIST","errorMessage":"DATABASE_TABLE_NAME_EXIST","messagePattern":"DATABASE_TABLE_NAME_EXIST","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"warning","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java","lineNumber":293,"sourceCode":"        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()) {\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()) {","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L275-L311","documentation":"Thrown by DatabaseService.createDbTable when a non-deleted table with the same name already exists in the target database (count query on name+dbId+deleted=false returns > 0). Table names must be unique within a database, so the DDL is never issued. It is an expected, user-facing validation error.","triggerScenarios":"createDbTable called with a name equal to an existing non-deleted table in the same db; retrying a create that already succeeded; case-variant names that the DB treats as duplicates.","commonSituations":"Double-click on 'create table'; re-running an import/seed script without idempotency; renaming semantics where the old table still exists under a similar name; copy of table definitions across databases with same names in the target.","solutions":["List existing tables in the database and pick a unique name","Reuse or alter the existing table instead of creating a new one","Delete the old table if it is no longer needed, then retry","Make bulk-creation scripts idempotent (skip existing names)"],"exampleFix":"// before\nDbTableDto dto = new DbTableDto();\ndto.setDbId(dbId);\ndto.setName(\"events\"); // may already exist\ndatabaseService.createDbTable(dto);\n// after\nlong exists = dbTableMapper.selectCount(new QueryWrapper<DbTable>().lambda()\n    .eq(DbTable::getName, \"events\").eq(DbTable::getDbId, dbId).eq(DbTable::getDeleted, false));\nif (exists == 0) { databaseService.createDbTable(dto); }","handlingStrategy":"validation","validationCode":"long dup = dbTableMapper.selectCount(new QueryWrapper<DbTable>().lambda()\n    .eq(DbTable::getName, name).eq(DbTable::getDbId, dbId).eq(DbTable::getDeleted, false));\nif (dup > 0) { /* choose another table name */ }","typeGuard":null,"tryCatchPattern":"try { databaseService.createDbTable(dto); } catch (BusinessException e) { if (\"DATABASE_TABLE_NAME_EXIST\".equals(e.getCode())) { /* prompt for a new name or reuse existing table */ } else { throw e; } }","preventionTips":["Check existing table names in the UI as the user types","Make seed/import scripts idempotent","Debounce create buttons to prevent duplicate submits"],"tags":["duplicate","uniqueness","database","validation","java"],"backgroundTag":"file-already-exists","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"}