{"record":{"id":"7a6bb511ba9547ae","repo":"flipped-aurora/gin-vue-admin","slug":"d-gvamodel-false-primarykey-true-7a6bb5","errorCode":null,"errorMessage":"模块 %d：当 gvaModel=false 时，只能有一个字段的 primaryKey=true","messagePattern":"模块 (.+?)：当 gvaModel=false 时，只能有一个字段的 primaryKey=true","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/gva_execute.go","lineNumber":408,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\tif associationValue != 1 && associationValue != 2 {\n\t\t\t\t\t\treturn fmt.Errorf(\"模块 %d 字段 %d 的 dataSource.association 必须是 1 或 2\", moduleIndex+1, i+1)\n\t\t\t\t\t}\n\t\t\t\t}\n\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,","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/gva_execute.go#L390-L426","documentation":"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.","triggerScenarios":"Module with gvaModel=false where two or more fields are flagged primaryKey=true (e.g. both id and code).","commonSituations":"LLM marks several candidate keys; template duplication when merging field lists; author confusing composite-key intent with the generator's single-key constraint.","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"],"exampleFix":"// before\n{\"fields\":[{\"fieldJson\":\"id\",\"primaryKey\":true},{\"fieldJson\":\"code\",\"primaryKey\":true}]}\n// after\n{\"fields\":[{\"fieldJson\":\"id\",\"primaryKey\":true},{\"fieldJson\":\"code\",\"primaryKey\":false}]}","handlingStrategy":"validation","validationCode":"pk := 0\nfor _, f := range m.Fields { if f.PrimaryKey { pk++ } }\nif pk > 1 { return fmt.Errorf(\"module %s has %d primaryKey fields, max 1\", m.Name, pk) }","typeGuard":"func singlePrimaryKey(m Module) bool {\n  n := 0\n  for _, f := range m.Fields { if f.PrimaryKey { n++ } }\n  return n <= 1\n}","tryCatchPattern":null,"preventionTips":["Exactly one primaryKey per custom module","Model composite keys via unique indexes instead","Lint merged/duplicated field lists for stray primaryKey flags"],"tags":["validation","primary-key","code-generator"],"backgroundTag":"missing-primary-key","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}