I have been getting this error as of lately while using room database. It tells me to upgrader the room version, but when I do this I get another error.
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.
This is what I get when changing the database version number from: version = 1 -> version = 2.
java.lang.IllegalStateException: A migration from 1 to 2 was required but not found. Please provide the necessary Migration path via RoomDatabase.Builder.addMigration(Migration ...) or allow for destructive migrations via one of the RoomDatabase.Builder.fallbackToDestructiveMigration* methods.
How can I solve this ?
Related
I've been trying to set up GraphQL for my android kotlin project with AWS Amplify, but I am getting red warning for #model as well as AuthRule & allow in:
This is the example TODO GraphQL schema, but when I do edit the schema, the issue still occurs. I'm wondering if I am missing something else that I didn't see in the documentation?
When I hover over #model, I see a Unknown directive "model" error message.
I tried to uninstalling and installing again the amplify add api. The error continues, and after searching through online, I don't see any solutions that are recent that can help with this.
I have an DB migration:
val MIGRATION_8_9 = object : Migration(8, 9) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE RideEntity RENAME frontVideoPresent TO frontVideoState")
database.execSQL("ALTER TABLE RideEntity RENAME rearVideoPresent TO rearVideoState")
}
}
When testing this migration on local Samsung phones it worked fine. The in production with help of craslytics I seen this crash:
Fatal Exception: java.lang.RuntimeException
Exception while computing database live data.
Caused by android.database.sqlite.SQLiteException
near "frontVideoPresent": syntax error (Sqlite code 1 SQLITE_ERROR): , while
compiling: ALTER TABLE RideEntity RENAME frontVideoPresent TO frontVideoState, (OS
error - 11:Try again)
This is happened on Huawei Mate 20 phone. How to understand better this crash? This is OS related?
I can not remove the rename now, because many users that updated the app the column renaming worked, but users with Huawei phones may suffer this crash.
I am open to your suggestions...
Looks like version of sqlite on some devices doesn't support column renaming because android app use build-in version on sqlite library to android OS. That's why version of sqlite depends on android's api level version (where app running). According to sqlite release notes (paragraph 2) the support for renaming columns was added in version 3.25.0 and according to google docs (and other answer on stackoverflow)the column's renaming on android supports since android api level 30.
To solve the problem of fragmentation of slqlite library you can use android-requery which allows to use last version of sqlile in all android versions(since API level 14). It's easy to use this library with room.
I am using data binding without any problems and it works good. But sometimes it frustrate me a lot by hiding the real problem by showing data binding error for no reason. Last time i made some changes in room database and mistakenly used wrong table name in ROOM DAO. At the time of building project android studio displayed multiple data binding error for no reason but not the real culprit ( wrong table name ). When i fixed that build worked. Now again i have made some changes and its giving me same data binding error, i am going through each file to find the real culprit but didn't see anything problematic. Any help to show all the error not just data binding error. This is very annoying Android Studio gradle build did not display all error at the bottom.
The Java compiler cuts off errors after 100 by default. With a standard Android-style project structure, add this to your root level build.gradle to raise the limit (to 500 in this case) - this raises the limit for all subprojects. You will still have to dig through all errors to find the real ones:
subprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xmaxerrs' << '500'
}
}
}
I fixed the issue by implementing Room in another module
You all have probably seen that ActiveAndroid has schema migrations which are specified as <db_version>.sql files in the assets/migrations folder.
I have a db version 2, with a migration file 2.sql
Does my next version have to be 3 and migration 3.sql, or can I do something like:
DB version - 2.1
Migration file: 2.1.sql ?
I just tested it, it throw's an exception:
java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Integer
So I guess it has to be an integer.
But that raises another question, can I increment the version by two points instead of just one?
For e.g. migration1: 2.sql
Migration2: 4.sql ?
I found some articles with the same error but solution did not work, I tried the following:
Can't downgrade database from version 2 to 1
solution: "you need to override onDowngrade" that does not apply to my code , because my database class does not extend anything.