flipped-aurora/gin-vue-admin · error
已经创建过此数据结构或重复简称,请勿重复创建!
Error message
已经创建过此数据结构或重复简称,请勿重复创建!
What it means
autoCodeTemplate.Preview checks AutocodeHistory.Repeat for the given business DB, struct name, abbreviation, and package; if a matching history exists and the request did not opt in via IsAdd, preview is blocked with "已经创建过此数据结构或重复简称,请勿重复创建!" (structure already created or duplicate abbreviation, do not duplicate). Unlike Create it also flags duplicate abbreviations.
Source
Thrown at server/service/system/auto_code_template.go:131
fileTask, err := prepareAutoCodeFileTask(layout, files)
if err != nil {
return err
}
return commitAutoCodeFileTask(fileTask, publishPreparedAutoCodeFile, func() error {
return persistAutoCodeMetadata(createCtx, global.GVA_DB, info, autoPkg.Template, history)
})
}
// Preview 预览自动化代码
func (s *autoCodeTemplate) Preview(ctx context.Context, info request.AutoCode) (map[string]string, error) {
var entity model.SysAutoCodePackage
err := global.GVA_DB.WithContext(ctx).Where("package_name = ?", info.Package).First(&entity).Error
if err != nil {
return nil, errors.Wrap(err, "查询包失败!")
}
// 增加判断: 重复创建struct 或者重复的简称
if AutocodeHistory.Repeat(ctx, info.BusinessDB, info.StructName, info.Abbreviation, info.Package) && !info.IsAdd {
return nil, errors.New("已经创建过此数据结构或重复简称,请勿重复创建!")
}
preview := make(map[string]string)
codes, _, _, err := s.generate(ctx, info, entity)
if err != nil {
return nil, err
}
for key, writer := range codes {
if len(key) > len(global.GVA_CONFIG.AutoCode.Root) {
key, _ = filepath.Rel(global.GVA_CONFIG.AutoCode.Root, key)
}
// 获取key的后缀 取消.
suffix := filepath.Ext(key)[1:]
var builder strings.Builder
builder.WriteString("```" + suffix + "\n\n")
builder.WriteString(writer.String())
builder.WriteString("\n\n```")
preview[key] = builder.String()View on GitHub (pinned to 3136500ef3)
Solutions
- Set info.IsAdd = true in the request to allow regeneration/preview of an existing structure.
- Change the abbreviation to a unique value if it collides with another struct.
- Remove the obsolete autocode history entry if the old structure is no longer wanted.
- Use a different package if the struct legitimately belongs elsewhere.
Example fix
// before
{"structName":"User","abbreviation":"user","isAdd":false}
// after
{"structName":"User","abbreviation":"user","isAdd":true} Defensive patterns
Strategy: validation
Validate before calling
if AutocodeHistory.Repeat(ctx, info.BusinessDB, info.StructName, info.Abbreviation, info.Package) && !info.IsAdd {
return errors.New("结构或简称已存在, 请设置 isAdd=true 或更换简称")
}
// safe to call Preview Try / catch
codes, err := autoCodeService.PreviewAutoCode(ctx, info)
if err != nil {
if strings.Contains(err.Error(), "重复简称") {
return fmt.Errorf("请设置 isAdd=true 或更换 abbreviation: %w", err)
}
return err
} Prevention
- Set isAdd=true when intentionally regenerating an existing structure.
- Enforce unique abbreviations per package in the form UI.
- Review autocode history before previewing a previously generated table.
- Remove obsolete history entries when structures are retired.
When it happens
Trigger: Previewing generation for a struct/abbreviation that already has autocode history without setting IsAdd=true; reusing an abbreviation already taken by another struct in the same package.
Common situations: Iterating on a previously generated table and previewing again without the add/overwrite flag; two structs sharing an abbreviation (e.g. both "user") causing model file name collisions.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/42467de2e660a129.
Report an issue: GitHub.