# sqlalchemy.exc.InvalidRequestError: 一个或多个映射器初始化失败——无法继续初始化其他映射器。原始异常：sqlalchemy.exc.NoReferencedTableError: 与列 'association.user_id' 关联的外键找不到表 'users' 来生成指向目标列 'id' 的外键。

- **ID:** `python/sqlalchemy-many-to-many-secondary-undefined`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在多对多关系中，关联表的外键引用了尚未定义或导入的表。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Ensure all referenced models are imported before configuring mappers: from myapp.models import User, Post, association_table
   ```
2. **** (85% 成功率)
   ```
   Use string table names in ForeignKey: Column('user_id', ForeignKey('users.id')) - and make sure users table is defined.
   ```

## 无效尝试

- **** — If the referenced table is in another module, simple reordering within one file won't help. (60% 失败率)
- **** — Breaks the relationship. (90% 失败率)
