# IllegalStateException：Room 无法验证数据完整性。看起来您更改了架构但忘记更新版本号。您可以通过增加版本号来修复此问题。

- **ID:** `android/room-migration-not-found`
- **领域:** android
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 87%

## 根因

Room 数据库架构已更改（例如添加了列），但版本号未增加或未提供迁移，导致完整性检查失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Room 2.4.0 | active | — | — |
| Room 2.5.0 | active | — | — |
| Room 2.6.0 | active | — | — |

## 解决方案

1. ```
   Increment database version and add migration: `@Database(entities = [User::class], version = 2)` and `val MIGRATION_1_2 = object : Migration(1, 2) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("ALTER TABLE User ADD COLUMN age INTEGER NOT NULL DEFAULT 0") } }`
   ```
2. ```
   Use `autoMigrations` annotation: `@Database(entities = [User::class], version = 2, autoMigrations = [AutoMigration(from = 1, to = 2)])` for simple changes like adding columns with defaults.
   ```
3. ```
   Export schema to JSON using `room.schemaLocation` in build.gradle, then use Room's automatic migration validator to detect issues.
   ```

## 无效尝试

- **Delete app data or uninstall app** — Loses all user data; only works for development, not production. (60% 失败率)
- **Set fallbackToDestructiveMigration() in Room database builder** — Destroys existing database on version mismatch, causing data loss; not suitable for production. (75% 失败率)
- **Ignore the error and continue** — App crashes on database access; cannot proceed without fixing migration. (95% 失败率)
