I have a problem when trying to write example test for room migration. When I run test i got above exception, however the table that causes the problem did not change between db versions.
Expected: TableInfo{name='UserSettings', columns={userLocalId=Column{name='userLocalId', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1, defaultValue='null'}, value=Column{name='value', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, key=Column{name='key', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=2, defaultValue='null'}}, foreignKeys=[], indices=[]}
found: TableInfo{name='UserSettings', columns={userLocalId=Column{name='userLocalId', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1, defaultValue='null'}, value=Column{name='value', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}, key=Column{name='key', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1, defaultValue='null'}}, foreignKeys=[], indices=null}
I can see the difference between found and expecteded but I dont know what caused it. My UserSettings.kt class:
@Entity(tableName = "UserSettings", primaryKeys = ["userLocalId", "key"])
data class UserSettingsEntity(
@ColumnInfo(name = "userLocalId") val userLocalId: String,
@ColumnInfo(name = "key") val key: String,
@ColumnInfo(name = "value") val value: String
)
Edit Found out its known issue for Roboelectric and migration tests. Error on room database migration test, due to a wrong "primaryKeyPosition" value
it's typo error , please check word type for column name value
value=Column{name='value', tye='TEXT', affinity='2', notNull=true