我正在尝试使用新的房间资料库,但出现此错误
RoomDatabase.kt
@Database(entities = TrolleyType::class), version = 2)
abstract class AppDatabase : RoomDatabase() {
abstract fun stationDao(): StationDao
}
MyDao.kt
@Dao
interface MyDao {
@get:Query("SELECT * FROM Station")
val stations: List<Station>
@get:Query("SELECT * FROM TrolleyType")
val trolleyTypes: List<TrolleyType>
}
实体
@Entity
data class Station(
@PrimaryKey @ColumnInfo(name = "_id") var id: Int = 0,
@ColumnInfo(name = "StationName") var stationName: String? = "",
@ColumnInfo(name = "StationArabic") var stationArabic: String? = ""
)
@Entity
data class TrolleyType(
@PrimaryKey @ColumnInfo(name = "_id") var id: Int = 0,
@ColumnInfo(name = "Type") var stationName: String? = "",
@ColumnInfo(name = "TypeArabic") var stationArabic: String? = ""
)
最佳答案
原来,我只是忘记了将Station实体添加到RoomDatabase
添加后,一切正常
@Database(entities = TrolleyType::class, Station::class), version = 2)
abstract class AppDatabase : RoomDatabase() {
abstract fun stationDao(): StationDao
}
关于android - 尝试使用 session 室库时出错。 [SQLITE_ERROR] SQL错误或缺少数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45170399/