{
  "id": "android/room-cursor-mismatch-column-type",
  "signature": "android.database.sqlite.SQLiteException: Cannot read from cursor: column 'price' has type REAL but expected INTEGER (code 0 SQLITE_MISMATCH)",
  "signature_zh": "android.database.sqlite.SQLiteException：无法从游标读取：列 'price' 的类型为 REAL，但应为 INTEGER（代码 0 SQLITE_MISMATCH）",
  "regex": "SQLiteException.*Cannot read from cursor: column.*has type.*but expected",
  "domain": "android",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "Room entity defines a column as an integer type (e.g., Int or Long) in Kotlin/Java, but the actual SQLite column contains a floating-point value (REAL) due to a migration failure or direct database manipulation.",
  "root_cause_type": "generic",
  "root_cause_zh": "Room 实体在 Kotlin/Java 中将列定义为整数类型（例如 Int 或 Long），但由于迁移失败或直接数据库操作，实际的 SQLite 列包含浮点值（REAL）。",
  "versions": [
    {
      "version": "Room 2.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Room 2.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "SQLite 3.32.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This only works during development; in production, users lose all local data. The underlying schema mismatch returns when migration is reapplied.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing the entity type alone does not fix the existing data; Room still reads the column as REAL, and the migration must handle type conversion explicitly.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Create a manual migration in your RoomDatabase class that converts the column type. For example: `val MIGRATION_1_2 = object : Migration(1, 2) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL(\"ALTER TABLE products ADD COLUMN price_new INTEGER\") database.execSQL(\"UPDATE products SET price_new = CAST(price AS INTEGER)\") database.execSQL(\"ALTER TABLE products DROP COLUMN price\") database.execSQL(\"ALTER TABLE products RENAME COLUMN price_new TO price\") } }`",
      "success_rate": 0.9,
      "how": "Create a manual migration in your RoomDatabase class that converts the column type. For example: `val MIGRATION_1_2 = object : Migration(1, 2) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL(\"ALTER TABLE products ADD COLUMN price_new INTEGER\") database.execSQL(\"UPDATE products SET price_new = CAST(price AS INTEGER)\") database.execSQL(\"ALTER TABLE products DROP COLUMN price\") database.execSQL(\"ALTER TABLE products RENAME COLUMN price_new TO price\") } }`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `@ColumnInfo(typeAffinity = ColumnInfo.REAL)` in your entity to match the actual column type, then handle the conversion in your app logic (e.g., `price.toInt()`).",
      "success_rate": 0.8,
      "how": "Use `@ColumnInfo(typeAffinity = ColumnInfo.REAL)` in your entity to match the actual column type, then handle the conversion in your app logic (e.g., `price.toInt()`).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Create a manual migration in your RoomDatabase class that converts the column type. For example: `val MIGRATION_1_2 = object : Migration(1, 2) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL(\"ALTER TABLE products ADD COLUMN price_new INTEGER\") database.execSQL(\"UPDATE products SET price_new = CAST(price AS INTEGER)\") database.execSQL(\"ALTER TABLE products DROP COLUMN price\") database.execSQL(\"ALTER TABLE products RENAME COLUMN price_new TO price\") } }`",
    "Use `@ColumnInfo(typeAffinity = ColumnInfo.REAL)` in your entity to match the actual column type, then handle the conversion in your app logic (e.g., `price.toInt()`)."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.android.com/training/data-storage/room/migrating-dbversions",
  "official_doc_section": null,
  "error_code": "SQLITE_MISMATCH",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.82,
  "resolvable": "true",
  "first_seen": "2023-09-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}