# sqlalchemy.exc.ArgumentError: relationship 'User.posts' 期望一个类或映射器参数（收到：<class 'str'>）

- **ID:** `python/sqlalchemy-invalid-relationship-argument`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

向 relationship() 传递了字符串，但未在正确的字符串解析上下文中，例如使用了不存在的类名。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.4.x | active | — | — |
| 2.0.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Ensure the class is defined before the relationship: class Post(Base): ...; class User(Base): posts = relationship(Post)
   ```
2. **** (85% 成功率)
   ```
   Use string with full module path if using declarative: posts = relationship('myapp.models.Post')
   ```

## 无效尝试

- **** — If the class is not yet defined, it will raise NameError. (80% 失败率)
- **** — NameError occurs because the class is not in scope. (90% 失败率)
