# 错误：proto：必填字段"user_id"未设置

- **ID:** `go/grpc-protobuf-required-field-missing`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

具有必填字段（proto2语法）的protobuf消息在反序列化时缺少必填字段。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0 | active | — | — |

## 解决方案

1. **Migrate from proto2 to proto3 where all fields are optional.** (90% 成功率)
   ```
   syntax = "proto3";
message UserRequest { string user_id = 1; }
   ```
2. **Ensure sender populates all required fields before sending.** (85% 成功率)
   ```
   if msg.UserId == nil { return errors.New("user_id required") }
   ```

## 无效尝试

- **Make the field optional in proto2 without changing schema.** — Required is a proto2 concept; cannot be removed without schema change. (90% 失败率)
- **Set a default value for the field.** — Required fields must be explicitly set by sender. (95% 失败率)
