# sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'association.user_id' could not find table 'users' with which to generate a foreign key to target column 'id'

- **ID:** `python/sqlalchemy-many-to-many-secondary-undefined`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

In a many-to-many relationship, the secondary table's foreign keys reference tables that are not yet defined or imported.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.4.x | active | — | — |
| 2.0.x | active | — | — |

## Workarounds

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

## Dead Ends

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