1
android
data_error
ai_generated
true
android.database.sqlite.SQLiteException:没有这样的表:users(代码 1 SQLITE_ERROR):编译时:SELECT * FROM users
android.database.sqlite.SQLiteException: no such table: users (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM users
ID: android/room-cursor-not-found
85%修复率
85%置信度
1证据数
2023-03-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Room 2.5.0 | active | — | — | — |
| Room 2.6.0 | active | — | — | — |
根因分析
Room 数据库迁移失败或架构版本不匹配,导致当前数据库中不存在该表。
English
Room database migration failed or the schema version is mismatched, causing the table to not exist in the current database.
官方文档
https://developer.android.com/training/data-storage/room/migrating解决方案
-
向 Room 数据库构建器添加正确的迁移。示例:Room.databaseBuilder(context, AppDatabase.class, "my-db").addMigrations(MIGRATION_1_2).build(); 其中 MIGRATION_1_2 是创建表的 Migration 对象。
-
使用 fallbackToDestructiveMigration() 重新创建数据库,但这会删除现有数据。仅在开发中或可接受数据丢失时使用。
-
导出架构并验证 JSON 文件与实体匹配。添加 @Database(entities = {User.class}, version = 2, exportSchema = true) 并检查 app/schemas/ 中生成的架构。
无效尝试
常见但无效的做法:
-
60% 失败
This only works if the database version is reset; if the schema is still incorrect, the error persists.
-
85% 失败
Room manages schema versions; manual changes cause version conflicts and data loss.
-
90% 失败
Room will throw an IllegalStateException about missing migration or fallback to destructive migration if configured.