flipped-aurora/gin-vue-admin · error
模块 %d:当 gvaModel=false 时,只能有一个字段的 primaryKey=true
Error message
模块 %d:当 gvaModel=false 时,只能有一个字段的 primaryKey=true
What it means
Companion to the missing-primary-key check: with gvaModel=false, at most one field may have primaryKey=true. Multiple primaryKey fields would produce an invalid single-column primary key in the generated model, so the plan is rejected.
Source
Thrown at server/mcp/gva_execute.go:408
}
if associationValue != 1 && associationValue != 2 {
return fmt.Errorf("模块 %d 字段 %d 的 dataSource.association 必须是 1 或 2", moduleIndex+1, i+1)
}
}
}
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,View on GitHub (pinned to 3136500ef3)
Solutions
- Keep exactly one field with primaryKey=true and remove the flag from the rest
- If composite identity is needed, model it with a unique index/constraint instead of multiple primaryKeys
- Regenerate the plan with an instruction that gvaModel=false allows only one primaryKey field
Example fix
// before
{"fields":[{"fieldJson":"id","primaryKey":true},{"fieldJson":"code","primaryKey":true}]}
// after
{"fields":[{"fieldJson":"id","primaryKey":true},{"fieldJson":"code","primaryKey":false}]} Defensive patterns
Strategy: validation
Validate before calling
pk := 0
for _, f := range m.Fields { if f.PrimaryKey { pk++ } }
if pk > 1 { return fmt.Errorf("module %s has %d primaryKey fields, max 1", m.Name, pk) } Type guard
func singlePrimaryKey(m Module) bool {
n := 0
for _, f := range m.Fields { if f.PrimaryKey { n++ } }
return n <= 1
} Prevention
- Exactly one primaryKey per custom module
- Model composite keys via unique indexes instead
- Lint merged/duplicated field lists for stray primaryKey flags
When it happens
Trigger: Module with gvaModel=false where two or more fields are flagged primaryKey=true (e.g. both id and code).
Common situations: LLM marks several candidate keys; template duplication when merging field lists; author confusing composite-key intent with the generator's single-key constraint.
Related errors
- 模块 %d:当 gvaModel=false 时,必须有一个字段的 primaryKey=true
- Package为空!
- 缺少任务 ID
- 模块 %d 字段 %d 的 columnName 不能为空
- 模块 %d 字段 %d 的 fieldType '%s' 不支持
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/7a6bb511ba9547ae.
Report an issue: GitHub.