I want to do a simple change on my room database: adding a new table.
My room version is: 2.4.1
According to https://medium.com/androiddevelopers/room-auto-migrations-d5370b0ca6eb, this task should be easy using an auto-migration.
Here is what the relevant part of my DB class looks before the migration:
@Database(
entities = [FlashCard::class, Pool::class],
version = 2
)
abstract class DB : RoomDatabase() {
...
For the migration, I changed that part to:
@Database(
entities = [FlashCard::class, Pool::class, FlashCardRunEvent::class],
version = 3,
autoMigrations = [
AutoMigration (from = 2, to = 3)
]
)
abstract class DB : RoomDatabase() {
...
It all compiles fine. The app runs until the first interaction with the database.
Then, the app crashes and I get this in my log:
Caused by: java.lang.IllegalStateException: Migration didn't properly handle: FlashCardRunEvent(com.ravenala.flashy.room.FlashCardRunEvent).
Expected:
TableInfo{name='FlashCardRunEvent', columns={newBox=Column{name='newBox', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, flashCardId=Column{name='flashCardId', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, timeStampInSeconds=Column{name='timeStampInSeconds', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, id=Column{name='id', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=1, defaultValue='null'}, oldBox=Column{name='oldBox', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}
Found:
TableInfo{name='FlashCardRunEvent', columns={}, foreignKeys=[], indices=[]}
I do not know what to make out of this. What's up with that difference between "Expected" and "Found". I had hoped room would simply see the new table, generate a scheme out of it and create the table. Are the times of writing SQL statements for simple migrations as this one not over?

