# android.database.sqlite.SQLiteException：没有这样的表：users（代码 1 SQLITE_ERROR）：编译时：SELECT * FROM users

- **ID:** `android/room-cursor-not-found`
- **领域:** android
- **类别:** data_error
- **错误码:** `1`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Room 数据库迁移失败或架构版本不匹配，导致当前数据库中不存在该表。

## 版本兼容性

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

## 解决方案

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/ 中生成的架构。
   ```

## 无效尝试

- **** — This only works if the database version is reset; if the schema is still incorrect, the error persists. (60% 失败率)
- **** — Room manages schema versions; manual changes cause version conflicts and data loss. (85% 失败率)
- **** — Room will throw an IllegalStateException about missing migration or fallback to destructive migration if configured. (90% 失败率)
