# android.database.sqlite.SQLiteException: Invalid column type (code 0): Cannot read column 'timestamp' as a long (code 0) at /path/to/RoomDatabase.kt:123

- **ID:** `android/room-invalid-cursor-query`
- **Domain:** android
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

Room's generated DAO implementation tries to read a column with a type that does not match the expected Java/Kotlin type, often due to a schema mismatch or incorrect converter.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Room 2.4.0 | active | — | — |
| Room 2.5.0 | active | — | — |
| Room 2.6.0 | active | — | — |
| Room 2.7.0 | active | — | — |
| Android 8.0 | active | — | — |
| Android 9 | active | — | — |
| Android 10 | active | — | — |
| Android 11 | active | — | — |
| Android 12 | active | — | — |
| Android 13 | active | — | — |
| Android 14 | active | — | — |
| Android 15 | active | — | — |

## Workarounds

1. **Check the entity and database version. If the column type changed, create a migration. Example: static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(@NonNull SupportSQLiteDatabase database) { database.execSQL("ALTER TABLE users ADD COLUMN timestamp INTEGER NOT NULL DEFAULT 0"); } }; Then add .addMigrations(MIGRATION_1_2) to the Room database builder.** (90% success)
   ```
   Check the entity and database version. If the column type changed, create a migration. Example: static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(@NonNull SupportSQLiteDatabase database) { database.execSQL("ALTER TABLE users ADD COLUMN timestamp INTEGER NOT NULL DEFAULT 0"); } }; Then add .addMigrations(MIGRATION_1_2) to the Room database builder.
   ```
2. **If the column type is correct but the converter is wrong, verify the TypeConverter. Example: @TypeConverter public static Long fromTimestamp(Long value) { return value == null ? null : value; } @TypeConverter public static Long dateToTimestamp(Long value) { return value; } Ensure both converters are symmetric and registered in @Database(entities = {...}, version = X, exportSchema = true).** (85% success)
   ```
   If the column type is correct but the converter is wrong, verify the TypeConverter. Example: @TypeConverter public static Long fromTimestamp(Long value) { return value == null ? null : value; } @TypeConverter public static Long dateToTimestamp(Long value) { return value; } Ensure both converters are symmetric and registered in @Database(entities = {...}, version = X, exportSchema = true).
   ```
3. **Use fallbackToDestructiveMigration() in the database builder for development: Room.databaseBuilder(context, AppDatabase.class, "db-name").fallbackToDestructiveMigration().build(); This recreates the database if no migration is found, but destroys data.** (70% success)
   ```
   Use fallbackToDestructiveMigration() in the database builder for development: Room.databaseBuilder(context, AppDatabase.class, "db-name").fallbackToDestructiveMigration().build(); This recreates the database if no migration is found, but destroys data.
   ```

## Dead Ends

- **Change the field type in the entity to match the error message, e.g., change long to String** — The error indicates an actual schema mismatch; changing the type without updating the database version and migration leads to a crash or data loss. (85% fail)
- **Delete the app data and reinstall without running migrations** — This destroys user data and is not suitable for production; it only works if the schema was never properly migrated. (80% fail)
- **Add @Ignore annotation to the problematic field** — Room will ignore the field entirely, potentially breaking queries that depend on it. (90% fail)
