# 无法为映射表 'orders' 组装任何主键列

- **ID:** `python/sqlalchemy-could-not-assemble-mapper`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

映射表缺少主键定义，可能因为没有列被标记为主键，或表继承自没有主键的 select。

## 版本兼容性

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

## 解决方案

1. **** (100% 成功率)
   ```
   class Order(Base):
    __tablename__ = 'orders'
    id = Column(Integer, primary_key=True)
    # other columns
   ```
2. **** (95% 成功率)
   ```
   class OrderItem(Base):
    __tablename__ = 'order_items'
    order_id = Column(Integer, ForeignKey('orders.id'), primary_key=True)
    product_id = Column(Integer, primary_key=True)
   ```

## 无效尝试

- **** — Column is just a regular column; SQLAlchemy still sees no primary key. (50% 失败率)
- **** — Unique constraints don't satisfy the primary key requirement for ORM mapping. (80% 失败率)
