{"record":{"id":"36dbebc1894b94a3","repo":"flipped-aurora/gin-vue-admin","slug":"d-gvamodel-true-d-primarykey-fal","errorCode":null,"errorMessage":"模块 %d：当 gvaModel=true 时，字段 %d 的 primaryKey 应该为 false","messagePattern":"模块 (.+?)：当 gvaModel=true 时，字段 (.+?) 的 primaryKey 应该为 false","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/gva_execute.go","lineNumber":413,"sourceCode":"\t\t\t}\n\n\t\t\tif !moduleInfo.GvaModel {\n\t\t\t\tprimaryKeyCount := 0\n\t\t\t\tfor _, field := range moduleInfo.Fields {\n\t\t\t\t\tif field.PrimaryKey {\n\t\t\t\t\t\tprimaryKeyCount++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif primaryKeyCount == 0 {\n\t\t\t\t\treturn fmt.Errorf(\"模块 %d：当 gvaModel=false 时，必须有一个字段的 primaryKey=true\", moduleIndex+1)\n\t\t\t\t}\n\t\t\t\tif primaryKeyCount > 1 {\n\t\t\t\t\treturn fmt.Errorf(\"模块 %d：当 gvaModel=false 时，只能有一个字段的 primaryKey=true\", moduleIndex+1)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor i, field := range moduleInfo.Fields {\n\t\t\t\t\tif field.PrimaryKey {\n\t\t\t\t\t\treturn fmt.Errorf(\"模块 %d：当 gvaModel=true 时，字段 %d 的 primaryKey 应该为 false\", moduleIndex+1, i+1)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// executeCreation 执行创建操作\nfunc (g *GVAExecutor) executeCreation(ctx context.Context, plan *ExecutionPlan) *ExecuteResponse {\n\tresult := &ExecuteResponse{\n\t\tSuccess:        false,\n\t\tPaths:          make(map[string]string),\n\t\tGeneratedPaths: []string{}, // 初始化生成文件路径列表\n\t}\n\n\t// 无论如何都先构建目录结构信息，确保paths始终返回","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/gva_execute.go#L395-L431","documentation":"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.","triggerScenarios":"Module entry with gvaModel=true whose fields list includes a field with primaryKey=true (typically a redundant id field).","commonSituations":"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.","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"],"exampleFix":"// before\n{\"gvaModel\":true,\"fields\":[{\"fieldJson\":\"id\",\"fieldType\":\"int\",\"columnName\":\"id\",\"primaryKey\":true}]}\n// after\n{\"gvaModel\":true,\"fields\":[]}","handlingStrategy":"validation","validationCode":"if m.GvaModel {\n  for i, f := range m.Fields {\n    if f.PrimaryKey { return fmt.Errorf(\"field %d must not set primaryKey when gvaModel=true\", i+1) }\n  }\n}","typeGuard":"func noExplicitPrimaryKey(m Module) bool {\n  for _, f := range m.Fields { if f.PrimaryKey { return false } }\n  return true\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["validation","primary-key","gva-model"],"backgroundTag":"missing-primary-key","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}