{"record":{"id":"e641277f86b160f0","repo":"flipped-aurora/gin-vue-admin","slug":"error-e64127","errorCode":null,"errorMessage":"已经创建过此数据结构,请勿重复创建!","messagePattern":"已经创建过此数据结构,请勿重复创建!","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_template.go","lineNumber":84,"sourceCode":"\n\t// Frontend files are published last, but their Vite refresh may still cancel\n\t// the HTTP request before the handler returns. The accepted create task must finish.\n\tcreateCtx := autoCodeCreateContext(ctx)\n\tvar autoPkg model.SysAutoCodePackage\n\terr := global.GVA_DB.WithContext(createCtx).Where(\"package_name = ?\", info.Package).First(&autoPkg).Error\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查询包失败!\")\n\t}\n\terr = s.checkPackage(info.Package, autoPkg.Template)\n\tif err != nil {\n\t\treturn err\n\t}\n\texists, err := autoCodeIdentityExists(createCtx, global.GVA_DB, info)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif exists {\n\t\treturn errors.New(\"已经创建过此数据结构,请勿重复创建!\")\n\t}\n\n\tlayout, err := newAutoCodeTaskLayout(\n\t\tglobal.GVA_CONFIG.AutoCode.Root,\n\t\tglobal.GVA_CONFIG.AutoCode.Server,\n\t\tglobal.GVA_CONFIG.AutoCode.WebRoot(),\n\t)\n\tif err != nil {\n\t\treturn err\n\t}\n\tgenerated, templates, injections, err := s.generate(createCtx, info, autoPkg)\n\tif err != nil {\n\t\treturn err\n\t}\n\thistory := info.History()\n\thistory.Templates = templates\n\thistory.Injections = make(map[string]string, len(injections))\n\tfor key, value := range injections {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_template.go#L66-L102","documentation":"autoCodeTemplate.Create first checks whether an autocode entry with the same identity (business DB, struct name, package/abbreviation) already exists via autoCodeIdentityExists. If it does, creation is refused with \"已经创建过此数据结构,请勿重复创建!\" (this data structure has already been created, do not duplicate it) to avoid generating duplicate code/history for the same table.","triggerScenarios":"POSTing the same autocode create request twice; creating a struct with the same structName/package for the same business DB; retrying after a failed run that already recorded history.","commonSituations":"Users double-clicking the generate button; importing the same table into autocode from two places; leftover history rows from a previous partially completed generation.","solutions":["Use the existing generated entry instead of re-creating it.","If you genuinely need a second structure, change structName (and abbreviation/package as appropriate) to unique values.","Clear stale autocode history rows for that table if a previous run failed and left an orphan record, then retry.","Set IsAdd/overwrite semantics where supported instead of a plain create."],"exampleFix":"// before: duplicate request\n{\"businessDB\":\"gva\",\"structName\":\"User\",\"package\":\"admin\"} // already exists\n// after: unique struct name\n{\"businessDB\":\"gva\",\"structName\":\"UserProfile\",\"package\":\"admin\"}","handlingStrategy":"validation","validationCode":"exists, err := autoCodeIdentityExists(ctx, db, info)\nif err == nil && exists {\n    return errors.New(\"该数据结构已存在, 请直接使用或更换 structName\")\n}\n// safe to call Create","typeGuard":null,"tryCatchPattern":"if err := autoCodeService.CreateAutoCode(ctx, info); err != nil {\n    if strings.Contains(err.Error(), \"请勿重复创建\") {\n        return fmt.Errorf(\"请改用已有条目或修改 structName/package: %w\", err)\n    }\n    return err\n}","preventionTips":["Search existing autocode entries before creating a new one.","Use unique structName/package per business table.","Clean up history rows after failed generations before retrying.","Debounce/double-click-guard the create button in the UI."],"tags":["autocode","duplicate","validation","business-logic"],"backgroundTag":"duplicate-record","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}