Android Room, wrong column name & column is not nullable

I´m using Room instead of classic sqlite statements now, and I´m having the following problems. When I open my "tags" Table, I´m getting the following error.

java.lang.IllegalStateException: Migration didn't properly handle tags(de.yochyo.ybooru.database.entities.Tag).
     Expected:
    TableInfo{name='tags', columns={name=Column{name='name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1}, type=Column{name='type', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, creation=Column{name='creation', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, isFavorite=Column{name='isFavorite', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
     Found:
    TableInfo{name='tags', columns={name=Column{name='name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1}, type=Column{name='type', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, Date=Column{name='Date', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0}, isFavorite=Column{name='isFavorite', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
        at de.yochyo.ybooru.database.Database_Impl$1.validateMigration(Database_Impl.java:81)
        at android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:87)
        at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:133)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:398)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
        at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:96)
        at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
        at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:233)
        at de.yochyo.ybooru.database.entities.TagDao_Impl.getAllTags(TagDao_Impl.java:142)
        at de.yochyo.ybooru.database.Database$tags$1$job$1.invokeSuspend(Database.kt:41)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
        at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)

The difference between what is expected and what was found is this

Expected:
creation=Column{name='creation', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}
Found:
Date=Column{name='Date', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0}

This is what my Tag class looks like.

@Entity(tableName = "tags")
class Tag(@PrimaryKey val name: String, val type: Int, var isFavorite: Boolean = false,@ColumnInfo(name = "creation") val creation: Date? = null)

There are two problems. The column-name (which should be "creation") is Date and my date column cannot contain null.

Does anyone know why this is happening?

1 answer

  • answered 2019-03-20 17:30 Yosh Five

    Fixed: "Expected" means that Room expected the table to contains those columns, "Found" are the columns in the database file.