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

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

https://developer.android.com/training/data-storage/room/migrating

解决方案

  1. 向 Room 数据库构建器添加正确的迁移。示例:Room.databaseBuilder(context, AppDatabase.class, "my-db").addMigrations(MIGRATION_1_2).build(); 其中 MIGRATION_1_2 是创建表的 Migration 对象。
  2. 使用 fallbackToDestructiveMigration() 重新创建数据库,但这会删除现有数据。仅在开发中或可接受数据丢失时使用。
  3. 导出架构并验证 JSON 文件与实体匹配。添加 @Database(entities = {User.class}, version = 2, exportSchema = true) 并检查 app/schemas/ 中生成的架构。

无效尝试

常见但无效的做法:

  1. 60% 失败

    This only works if the database version is reset; if the schema is still incorrect, the error persists.

  2. 85% 失败

    Room manages schema versions; manual changes cause version conflicts and data loss.

  3. 90% 失败

    Room will throw an IllegalStateException about missing migration or fallback to destructive migration if configured.