I am trying to use Room in Android Studio using Kotlin with a pre-packaged database. The database does not set NOT NULL. Using DB SQL Browser it shows that the column has these properties
"Reference" TEXT
There is no NOT NULL. All the other columns in the table do have NOT NULL set.
In the Entity that maps that table I have:
@Entity
data class Meaning (
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "Id") val id: Int,
@NonNull @ColumnInfo(name = "Contents") val contents: String,
/*
* It's OK for Reference to be Null
*/
@ColumnInfo(name = "Reference") val reference: String,
@NonNull @ColumnInfo(name = "SymbolId") val symbolId: Int,
@NonNull @ColumnInfo(name = "Local") val local: Int
)
It builds and installs, but fails when running with this error:
java.lang.IllegalStateException: Pre-packaged database has an invalid schema: Meaning(<stuff>.Meaning).
Expected:
TableInfo{name='Meaning', <unimportant columns>, Reference=Column{name='Reference', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'},<more unimportant columns>}
Found:
TableInfo{name='Meaning', <unimportant columns>, Reference=Column{name='Reference', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'}, <more unimportant columns}
Note that the Found has notNull=false, which seems correct because NOT NULL is not specified in the database. The Expected has notNull=true even though in the Entity, @NonNull was not specified for the Reference column.
So, I am confused why the Entity is expecting Reference column to be notNull=true.
Any pointers are welcome.