{"record":{"id":"884f7d807f7df996","repo":"iflytek/astron-agent","slug":"8514-database-table-delete-failed-cited","errorCode":"8514","errorMessage":"database.table.delete.failed.cited","messagePattern":"database\\.table\\.delete\\.failed\\.cited","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":643,"sourceCode":"                } catch (Exception e) {\n                    return 0;\n                }\n            case CommonConst.DBFieldType.BOOLEAN:\n                return Boolean.parseBoolean(v);\n            default:\n                return v; // Others as string\n        }\n    }\n\n\n    public void deleteTable(Long tbId) {\n        try {\n            DbTable dbTable = dbTableMapper.selectById(tbId);\n            dataPermissionCheckTool.checkDbBelong(dbTable.getDbId());\n            Long count = flowDbRelMapper.selectCount(new QueryWrapper<FlowDbRel>().lambda()\n                    .eq(FlowDbRel::getTbId, tbId));\n            if (count > 0) {\n                throw new BusinessException(ResponseEnum.DATABASE_TABLE_DELETE_FAILED_CITED);\n            }\n            DbInfo dbInfo = dbInfoMapper.selectById(dbTable.getDbId());\n            DbTableDto dbTableDto = new DbTableDto();\n            dbTableDto.setName(dbTable.getName());\n            String ddl = buildDDL(dbTableDto, DBOperateEnum.DELETE.getCode(), null);\n            // Delete from core system\n            for (String stmt : safeSplitStatements(ddl)) {\n                SqlRenderer.denyMultiStmtOrComment(stmt); // At this point each statement does not contain semicolon\n                coreSystemService.execDDL(stmt, UserInfoManagerHandler.getUserId(), SpaceInfoUtil.getSpaceId(), dbInfo.getDbId());\n            }\n            dbTableMapper.update(new UpdateWrapper<DbTable>().lambda()\n                    .eq(DbTable::getId, tbId)\n                    .set(DbTable::getDeleted, true));\n            // Delete table fields\n            dbTableFieldMapper.delete(new UpdateWrapper<DbTableField>().lambda()\n                    .eq(DbTableField::getTbId, tbId));\n        } catch (BusinessException ex) {\n            log.error(\"Failed to delete table, tbId={}\", tbId);","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L625-L661","documentation":"Thrown by DatabaseService.deleteTable when the table is still referenced by at least one workflow (flow). The service counts rows in flow_db_rel for the tbId (line 646-649) and refuses to delete a cited table to avoid breaking workflows that depend on it.","triggerScenarios":"Calling deleteTable(tbId) where flowDbRelMapper.selectCount for that tbId > 0, i.e. one or more workflows reference the table in their configuration.","commonSituations":"Attempting to clean up database tables while old workflows still use them; soft-deleted or draft workflows still holding references in flow_db_rel; team unaware that a shared table is wired into production workflows.","solutions":["Find and update/remove the workflows referencing the table (flow_db_rel rows for this tbId)","Delete or rewire the dependent workflow nodes before retrying deletion","If references are stale, clean the flow_db_rel entries for this tbId, then retry","Only delete the table once selectCount on FlowDbRel.tbId returns 0"],"exampleFix":"// before\ndeleteTable(tbId)  // fails: 3 workflows cite this table\n// after\n// first remove the table from all workflow nodes, then:\ndeleteTable(tbId)","handlingStrategy":"try-catch","validationCode":"long citations = flowDbRelMapper.selectCount(\n    new QueryWrapper<FlowDbRel>().lambda().eq(FlowDbRel::getTbId, tbId));\nif (citations > 0) {\n    throw new IllegalStateException(\"table is cited by \" + citations + \" workflow(s); detach first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    databaseService.deleteTable(tbId);\n} catch (BusinessException e) {\n    if (\"DATABASE_TABLE_DELETE_FAILED_CITED\".equals(e.getCode())) {\n        // list workflows referencing this table and inform the user\n    }\n    throw e;\n}","preventionTips":["Before deleting, query flow_db_rel for references to the tbId","Provide UI to show which workflows cite a table","Clean up stale workflow references when workflows are removed","Establish a decommission process: detach from workflows, then delete"],"tags":["database","referential-integrity","delete-blocked"],"backgroundTag":"operation-not-supported","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"}