flipped-aurora/gin-vue-admin · error
模块 %d:当 gvaModel=true 时,字段 %d 的 primaryKey 应该为 false
Error message
模块 %d:当 gvaModel=true 时,字段 %d 的 primaryKey 应该为 false
What it means
When gvaModel=true, the module uses the standard gin-vue-admin base model which already supplies the primary key (id, created_at, etc.), so user-declared fields must NOT set primaryKey=true. Any field that does is rejected.
Source
Thrown at server/mcp/gva_execute.go:413
}
if !moduleInfo.GvaModel {
primaryKeyCount := 0
for _, field := range moduleInfo.Fields {
if field.PrimaryKey {
primaryKeyCount++
}
}
if primaryKeyCount == 0 {
return fmt.Errorf("模块 %d:当 gvaModel=false 时,必须有一个字段的 primaryKey=true", moduleIndex+1)
}
if primaryKeyCount > 1 {
return fmt.Errorf("模块 %d:当 gvaModel=false 时,只能有一个字段的 primaryKey=true", moduleIndex+1)
}
} else {
for i, field := range moduleInfo.Fields {
if field.PrimaryKey {
return fmt.Errorf("模块 %d:当 gvaModel=true 时,字段 %d 的 primaryKey 应该为 false", moduleIndex+1, i+1)
}
}
}
}
}
return nil
}
// executeCreation 执行创建操作
func (g *GVAExecutor) executeCreation(ctx context.Context, plan *ExecutionPlan) *ExecuteResponse {
result := &ExecuteResponse{
Success: false,
Paths: make(map[string]string),
GeneratedPaths: []string{}, // 初始化生成文件路径列表
}
// 无论如何都先构建目录结构信息,确保paths始终返回View on GitHub (pinned to 3136500ef3)
Solutions
- Remove the redundant id/primaryKey field from the fields list — the base model provides id
- Or delete "primaryKey":true on that field, keeping only business columns
- Set gvaModel=false if you really need a custom primary key column
Example fix
// before
{"gvaModel":true,"fields":[{"fieldJson":"id","fieldType":"int","columnName":"id","primaryKey":true}]}
// after
{"gvaModel":true,"fields":[]} Defensive patterns
Strategy: validation
Validate before calling
if m.GvaModel {
for i, f := range m.Fields {
if f.PrimaryKey { return fmt.Errorf("field %d must not set primaryKey when gvaModel=true", i+1) }
}
} Type guard
func noExplicitPrimaryKey(m Module) bool {
for _, f := range m.Fields { if f.PrimaryKey { return false } }
return true
} Prevention
- Never include an id/primaryKey field when gvaModel=true — the base model supplies id
- Strip primaryKey flags when converting gvaModel=false modules to gvaModel=true
- Template the fields list per gvaModel mode
When it happens
Trigger: Module entry with gvaModel=true whose fields list includes a field with primaryKey=true (typically a redundant id field).
Common situations: Author copies a gvaModel=false module definition into a gvaModel=true one without removing the id/primaryKey field; LLM emits a uniform field template including a primaryKey id regardless of gvaModel.
Related errors
- 缺少任务 ID
- 模块 %d:当 gvaModel=false 时,必须有一个字段的 primaryKey=true
- 模块 %d:当 gvaModel=false 时,只能有一个字段的 primaryKey=true
- path 参数是必需的
- description 参数是必需的
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/36dbebc1894b94a3.
Report an issue: GitHub.