# android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: users.id (code 1555)

- **ID:** `android/room-insert-null-primary-key`
- **Domain:** android
- **Category:** data_error
- **Error Code:** `1555`
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

Room entity has a non-null primary key field that is not auto-generated, but null value is provided during insert.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Room 2.6.1 | active | — | — |
| SQLite 3.44.0 | active | — | — |
| Android 14 (API 34) | active | — | — |

## Workarounds

1. **Add @PrimaryKey(autoGenerate = true) to the id field. Example: @PrimaryKey(autoGenerate = true) val id: Long = 0. This auto-generates unique IDs.** (95% success)
   ```
   Add @PrimaryKey(autoGenerate = true) to the id field. Example: @PrimaryKey(autoGenerate = true) val id: Long = 0. This auto-generates unique IDs.
   ```
2. **If auto-generate not desired, ensure you assign a non-null value before insert: user.id = System.currentTimeMillis() or use UUID.randomUUID().toString() for string keys.** (85% success)
   ```
   If auto-generate not desired, ensure you assign a non-null value before insert: user.id = System.currentTimeMillis() or use UUID.randomUUID().toString() for string keys.
   ```

## Dead Ends

- **Set primary key field to nullable in entity class** — Room does not allow nullable primary keys; will cause compile error or runtime crash. (95% fail)
- **Use @Ignore on primary key field to skip Room processing** — Ignores the field entirely, but then no primary key exists, breaking database operations. (90% fail)
