- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从 Codelabs 学习如何使用 Room现在我有两张 table
当我从 Android Studio 运行时是正常的
但是当我关闭并重新打开应用程序时出现错误
java.lang.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.
重新打开应用程序时出错,而不是在安装时出错
我试图升级版本号,但我仍然遇到错误
这里是我的代码
@Database(entities = [Type::class], version = 3)
abstract class TypeRoomDb : RoomDatabase(){
abstract fun typeDao() : TypeDao
companion object{
@Volatile
private var INSTANCE : TypeRoomDb? = null
fun getDataBase(
context: Context,
scope: CoroutineScope
): TypeRoomDb {
return INSTANCE ?: synchronized(this){
val instance = Room.databaseBuilder(
context.applicationContext,
TypeRoomDb::class.java,
Cons.DB_NAME
)
.fallbackToDestructiveMigration()
.addCallback(TypeDbCallBack(scope))
.build()
INSTANCE = instance
instance
}
}
private class TypeDbCallBack(
private val scope: CoroutineScope
) : RoomDatabase.Callback(){
override fun onOpen(db: SupportSQLiteDatabase) {
super.onOpen(db)
INSTANCE?.let { database ->
scope.launch(Dispatchers.IO) {
populateDb(
database.typeDao()
)
}
}
}
}
fun populateDb(typeDao: TypeDao){
typeDao.deleteAll()
/*out*/
typeDao.insert(
Type(
"000",
"Makan",
0
)
)
typeDao.insert(
Type(
"001",
"Transportasi",
0
)
)
typeDao.insert(
Type(
"002",
"Makanan Ringan",
0
)
)
typeDao.insert(
Type(
"003",
"Komunikasi",
0
)
)
/*in*/
typeDao.insert(Type(
"500",
"Gaji",
1))
typeDao.insert(
Type(
"5001",
"Hadiah",
1
)
)
}
}
}
我的第二张 table
@Database(entities = [LogKeuangan::class], version = 2)
abstract class LogKeuanganRoomDb : RoomDatabase() {
abstract fun logKeuanganDao(): LogKeuanganDao
companion object {
@Volatile
private var INSTANCE: LogKeuanganRoomDb? = null
fun getDataBase(
context: Context,
scope: CoroutineScope
): LogKeuanganRoomDb {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
LogKeuanganRoomDb::class.java,
Cons.DB_NAME
)
.fallbackToDestructiveMigration()
.build()
INSTANCE = instance
instance
}
}
}
}
最佳答案
在
中清楚提到的一切java.lang.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.
您只需增加版本并将 exportSchema
设置为 false
来自
@Database(entities = [Type::class], version = 3)
到
@Database(entities = [Type::class], version = 4, exportSchema = false)
注意
@Database creates another db if you want all tables belongs same db then include them into one db. you should not create new db for each table
关于android - 重新打开应用程序时 Room 无法验证数据完整性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62017835/
我想要一些概念上的澄清。为了证明问题是 NP 完全的,我们使用归约。 现在假设我有 L<=L'。是从 L 减少到 L' 还是我也可以用相反的方式来减少?即我能否证明如果 L 可以使用 L' 求解,那么
考虑不相交的哈密顿路径问题: 输入:一个可能是有向或无向的图 输出:此图是否至少存在 2 条边不相交的哈密顿路径?边不相交意味着没有一条边被两条路径共享。 证明不相交哈密顿路径是 np-完全的。 有人
我理解为什么有界度生成树被认为是度数为 2 的 NP 完全(这是哈密顿路径问题的一个实例),但我不明白为什么这适用于度数 > 2。如果有人可以解释一下为什么这是大于 2 的 NP 完全问题,这将是最有
我正在实现一个 Django 网站,其中上传的文件在保存到服务器 (/media) 之前使用用户提供的 key 进行加密。当用户希望查看它们时,系统会提示他们输入 key ,加密文件被解密,然后显示给
我想用nodejs列出指定目录中的所有文件。 var fs = require('fs'); var path = require('path'); var walk = function(direc
在我的文件夹 assets/data 中,有很多包含我的应用静态数据的 XML 文件。 对于某人来说,检索 APK、修改其中的一部分并安装到设备上真的很容易。 我想通过检查我的 assets/data
我正在努力将我的备份脚本从 shell 转换为 Python。我的旧脚本的功能之一是通过执行以下操作检查创建的 tarfile 的完整性:gzip -t。 这在 Python 中似乎有点棘手。 似乎唯
我正在尝试将包含带有单独 CSS 和 js 文件的 HTML 脚本的 php 文件导入另一个包含我的页眉和页脚的 php 文件。页眉和页脚来自一个模板,该模板使用非常困惑和令人费解的 CSS,基本上对
使用 Flask,我试图验证 cookie 没有被篡改。现在,如果我更改 cookie 值,它只会抛出一个错误,但我想检查代码 is_valid(session['user_id']) 并重定向/重置
在 PHP(和 MySQL)中,我们有许多技术来确保输入的数据有效且安全。添加斜杠、MySQL 的转义字符串和正则表达式是我们经常使用的一些。 我已经看到此链接,该链接对该主题进行了非常初步的介绍,但
下面的代码使用了不安全的 GeneralizedNewtypeDeriving扩展中断 Data.Set通过插入具有不同 Ord 的不同元素实例: {-# LANGUAGE GeneralizedNe
我刚刚在 NPM 上创建了一个新包(这非常简单),我对如何维护包的完整性感兴趣。任何人都可以发布软件包的新版本吗?或者这仅限于我的用户帐户? 如果任何人都可以发布对包的更改,如何监控他们的修改以确保项
我正在尝试使用 Dapper 和 SQLite 来追踪 C# 项目中的数据库损坏错误。所以我正在寻找一种方法来检查代码中的数据库完整性。我发现多个地方说我可以为此发送命令“PRAGMAintegrit
yarn 安装抛出: EACCES: permission denied, unlink '/home/minnak/Darbas/market/node_modules/.yarn-integrit
上下文: 我有 open-sourced a repository ,由 Travis-CI 测试。特拉维斯提供 build-notification用于测试运行的钩子(Hook),因此您可以在 IR
我是一名优秀的程序员,十分优秀!