android
data_error
ai_generated
true
IllegalStateException:Room 无法验证数据完整性。看起来您更改了架构但忘记更新版本号。您可以通过增加版本号来修复此问题。
IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
ID: android/room-migration-not-found
87%修复率
89%置信度
1证据数
2023-12-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Room 2.4.0 | active | — | — | — |
| Room 2.5.0 | active | — | — | — |
| Room 2.6.0 | active | — | — | — |
根因分析
Room 数据库架构已更改(例如添加了列),但版本号未增加或未提供迁移,导致完整性检查失败。
English
Room database schema has changed (e.g., added column) but version number not incremented or migration not provided, causing integrity check failure.
官方文档
https://developer.android.com/training/data-storage/room/migrating解决方案
-
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") } }` -
Use `autoMigrations` annotation: `@Database(entities = [User::class], version = 2, autoMigrations = [AutoMigration(from = 1, to = 2)])` for simple changes like adding columns with defaults.
-
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
60% 失败
Loses all user data; only works for development, not production.
-
Set fallbackToDestructiveMigration() in Room database builder
75% 失败
Destroys existing database on version mismatch, causing data loss; not suitable for production.
-
Ignore the error and continue
95% 失败
App crashes on database access; cannot proceed without fixing migration.