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 migration, I am getting following error,
java.lang.IllegalStateException: Migration didn't properly handle.
Code I am using is as follows:
@Entity(tableName = ROUTE_TABLE)
public class RouteData {
static final String ROUTE_TABLE = "name";
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
private int id;
@ColumnInfo(name = "col1")
private String col1;
//Other columns with exactly same as 'col1' just different names
//Getters and Setters
}
For migration,
Room.databaseBuilder(context.getApplicationContext(), MyData.class, DATABASE_NAME)
.addMigrations(MIGRATION_LATEST)
.fallbackToDestructiveMigration()
.build();
private static final Migration MIGRATION_LATEST = new Migration(9, 10) {
@Override
public void migrate(SupportSQLiteDatabase db) {
//Log.i("Tag" , "Migration Started");
//Migration logic
//Log.i("Tag" , "Migration Ended");
}
};
When I run program. I get "Migration Ended" log in my LogCat but when I am trying access database again, it is giving me following error.
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=[]}
I have no idea where where this "INTEGER" is coming. I tried uninstalling, invalidating cache and any other closely related solution. Any idea what is going on? It works perfectly fine if you freshly install app. Error is coming up only after migration. According to my log cat, all migration steps seems to be completed but it is still showing migration not handled properly.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…