Obsolete
Status Update
Comments
da...@google.com <da...@google.com> #2
This is odd, when a DB is being opened and upgraded we detect if there are missing migrations and we throw an exception with a message along the lines of "A migration from $oldVersion to $newVersion was required but not found..." (see https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/room/runtime/src/main/java/androidx/room/RoomOpenHelper.java#101 ). My guess here is that something is catching and swallowing that exception. Do you have some catch some exception around your queries? Try to consider what might be the first query executed in your app, since its in the first DB interaction when the database is opened and upgraded. If an exception is swallowed during a migration and then another interaction occurs with the Database then you get that type of exception, where the DB didn't open (migration failed) yet you are trying to still use it.
de...@gmail.com <de...@gmail.com> #3
OK, let me elaborate a bit what happened to us. Our app ships with a so-called "seed database", which is a pre-populated SQLite DB that we generate every time we release (and whose schema is identical to the one modelled in code). Using a library, we make sure that upon a fresh install, we copy that file from the assets directory into the private app directory, and use that as our main database file from that point onwards.
While in the process of migrating from our old ORM Cupboard to Room, we released to beta and we noticed some users getting that `IllegalStateException` error. We managed to reproduce the issue and we found out that some users had really old columns in their table that nobody got rid of during the years. This was making Room detect a mismatch in the schema modelled in code, hence throwing the exception that I mentioned. The interesting part is that, in order to figure out this problem, we had to extract the "faulty" database file and use it as the "seed database" for a debuggable version of the app: this way, Room threw the following exception that put us on the right track:
```
Expected:
TableInfo{name='Book', columns={ ... }
Found:
TableInfo{name='Book', columns={ ... }
```
We had migrations that were covering all the database versions, the point is that those migrations didn't take into account some really old columns that were never removed. That's why I believe that Room is getting "confused" when it comes to the error it throws (I checked the sources, and it throws that while performing the consistency check over the tables).
I hope this offers a little bit more insight on this issue! Otherwise, I might try to reproduce it in a sample project, but it might take a while.
While in the process of migrating from our old ORM Cupboard to Room, we released to beta and we noticed some users getting that `IllegalStateException` error. We managed to reproduce the issue and we found out that some users had really old columns in their table that nobody got rid of during the years. This was making Room detect a mismatch in the schema modelled in code, hence throwing the exception that I mentioned. The interesting part is that, in order to figure out this problem, we had to extract the "faulty" database file and use it as the "seed database" for a debuggable version of the app: this way, Room threw the following exception that put us on the right track:
```
Expected:
TableInfo{name='Book', columns={ ... }
Found:
TableInfo{name='Book', columns={ ... }
```
We had migrations that were covering all the database versions, the point is that those migrations didn't take into account some really old columns that were never removed. That's why I believe that Room is getting "confused" when it comes to the error it throws (I checked the sources, and it throws that while performing the consistency check over the tables).
I hope this offers a little bit more insight on this issue! Otherwise, I might try to reproduce it in a sample project, but it might take a while.
Description
Version used: 2.1.0-rc01
Devices/Android versions reproduced on: irrelevant (all Android versions)
Whenever Room detects that a modification in the schema of the existing database without having the required migration information, it yields this very opaque error:
> java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: (database path)
This is highly uninformative and pretty misleading (see this StackOverflow answer:
I'm suggesting that, when this is the case, a more meaningful error is displayed. Ideally, highlighting what table is affected would be even better (like it's done when you provide a migration that is partial).