# sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: user.email

- **ID:** `python/flask-sqlalchemy-integrityerror`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to insert a duplicate value into a column with a UNIQUE constraint.

## Version Compatibility

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

## Workarounds

1. **** (85% success)
   ```
   if not User.query.filter_by(email=email).first():
    db.session.add(user)
    db.session.commit()
   ```
2. **** (90% success)
   ```
   from sqlalchemy.dialects.postgresql import insert
stmt = insert(User).values(email=email).on_conflict_do_nothing()
   ```

## Dead Ends

- **** — Silently fails to create the user, leading to inconsistent state. (70% fail)
- **** — Allows duplicate emails, breaking application logic. (90% fail)
