Caused by: java.lang.IllegalStateException: Migration didn’t properly handle: Expected
TableInfo{name=’project’, columns={venueName=Column{name=’venueName’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, nfcMerchantId=Column{name=’nfcMerchantId’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, nfcPrivateKey=Column{name=’nfcPrivateKey’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, endDate=Column{name=’endDate’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, scheduledAnonymisationDate=Column{name=’scheduledAnonymisationDate’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, nfcProfileId=Column{name=’nfcProfileId’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, name=Column{name=’name’, type=’TEXT’, affinity=’2′, notNull=true, primaryKeyPosition=0, defaultValue=’null’}, timeZone=Column{name=’timeZone’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, id=Column{name=’id’, type=’TEXT’, affinity=’2′, notNull=true, primaryKeyPosition=1, defaultValue=’null’}, uuid=Column{name=’uuid’, type=’TEXT’, affinity=’2′, notNull=true, primaryKeyPosition=0, defaultValue=’null’}, nfcCollectorId=Column{name=’nfcCollectorId’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, startDate=Column{name=’startDate’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}}, foreignKeys=[], indices=[Index{name=’index_project_uuid’, unique=false, columns=[uuid], orders=[ASC]}]}
Found
TableInfo{name=’project’, columns={venueName=Column{name=’venueName’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, endDate=Column{name=’endDate’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, scheduledAnonymisationDate=Column{name=’scheduledAnonymisationDate’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, nfcProfileId=Column{name=’nfcProfileId’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, name=Column{name=’name’, type=’TEXT’, affinity=’2′, notNull=true, primaryKeyPosition=0, defaultValue=’null’}, timeZone=Column{name=’timeZone’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}, id=Column{name=’id’, type=’TEXT’, affinity=’2′, notNull=true, primaryKeyPosition=1, defaultValue=’null’}, uuid=Column{name=’uuid’, type=’TEXT’, affinity=’2′, notNull=true, primaryKeyPosition=0, defaultValue=’null’}, startDate=Column{name=’startDate’, type=’TEXT’, affinity=’2′, notNull=false, primaryKeyPosition=0, defaultValue=’null’}}, foreignKeys=[], indices=[Index{name=’index_project_uuid’, unique=false, columns=[uuid], orders=[ASC]}]}
I have upgraded my app on top of the previous version and I got this error when I open the new upgraded version of my app. I have added migration class and added the newly added fields and also I have increased the database version. This is my entity class.
@Entity(
tableName = "project",
indices = [Index("uuid")]
)
data class ProjectEntity(
@PrimaryKey
val id: String,
val uuid: String,
val name: String,
val startDate: String?,
val endDate: String?,
val venueName: String?,
val timeZone: String?,
val scheduledAnonymisationDate: String?,
val nfcCollectorId: String?,
val nfcMerchantId: String?,
val nfcPrivateKey: String?,
val nfcProfileId: String?
)
This is my database class.
@Database(entities = {ProjectEntity.class}, version = 23)
public abstract class RoomDatabaseImpl extends RoomDatabase {
abstract fun projectDao(): ProjectDao
}
This is my migration class.
internal object Migration18To19 : Migration(18, 19) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE `project` ADD COLUMN `nfcCollectorId` TEXT")
database.execSQL("ALTER TABLE `project` ADD COLUMN `nfcMerchantId` TEXT")
database.execSQL("ALTER TABLE `project` ADD COLUMN `nfcPrivateKey` TEXT")
database.execSQL("ALTER TABLE `project` ADD COLUMN `nfcProfileId` TEXT")
}
}
and my current database version is 23.
I have also made few other changes in the other tables and added migration class for all that and incremented the database version accordingly. My current latest migration class is Migration22To23 and version is 23. I am not really sure why I am getting this error. Could someone help me to solve this issue?