I am scratching my head with this error. I couldn\'t find any answer so far. I have old database which I am migrating to Persistence Room library. However whenever I do migr
Thank you all for trying to help me, however I have finally found the answer after days of frustrating debugging. In my app manifest auto backup was on,
android:allowBackup="true"
So while trying out various databases, google was actually backing up my any newly created databases and their structure and restoring them automatically when I was reinstalling app. Hence I was getting this wired error. Once I switch of auto backup android:allowBackup="false"
and reinstall app, I can test migration properly.
My suggestion for all developers in future encountering such problem, SWITCH OFF auto backup while development. You can switch it on once you have tested your migration.
The main problem in your migration script is bellow:
Caused by: java.lang.IllegalStateException: Migration didn't properly handle xxx.
Expected:
TableInfo{name='name', columns={col1=Column{name='col1', type='TEXT', notNull=false, primaryKeyPosition=0}, ....}, foreignKeys=[]}
Found:
TableInfo{name='name', columns={col1=Column{name='col1', type='INTEGER', notNull=false, primaryKeyPosition=0}, ....}, foreignKeys=[]}
Here, in your Entity Class you have :
@ColumnInfo(name = "col1")
private String col1;
but in your migration query you may be adding col1
as INTEGER
From your error :
Expected :
columns={col1=Column{name='col1', type='TEXT', notNull=false, primaryKeyPosition=0}
Found :
columns={col1=Column{name='col1', type='INTEGER', notNull=false, primaryKeyPosition=0}
Solution: change your migration query like :
ALTER TABLE 'YOUR_TABLE' ADD COLUMN 'col1' TEXT
It will solve your problem.
Thanks :)