# sqlalchemy.orm.exc.UnmappedClassError: Class 'app.models.User' is not mapped

- **ID:** `python/sqlalchemy-orm-exc-unmapped-class-error`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The ORM class has not been properly registered with a Base or declarative base, or the module containing the class was not imported before session usage.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Correctly inherit from declarative base** (95% success)
   ```
   Ensure the class inherits from Base = declarative_base() and import it before any session operations.
   ```
2. **Create all tables to trigger mapping** (90% success)
   ```
   Call Base.metadata.create_all(engine) after defining all models to ensure mapping is established.
   ```

## Dead Ends

- **Adding decorators to the class** —  (60% fail)
- **Re-importing the class later** —  (50% fail)
