Skip to content Skip to sidebar Skip to footer

Pre-packaged Database Has An Invalid Schema Column Order

I am attempting to implement Room in my Android application, but am getting the error java.lang.IllegalStateException: Pre-packaged database has an invalid schema: viewLog(myApp.Vi

Solution 1:

I believe that your issue is not the order but rather the case of the column names.

For example the following database (save as asset appcase.db) defined with :-

CREATETABLE "viewLog" (
  "MID" INTEGERNOTNULL,
  "UTS" realNOTNULL,
  "VID" INTEGERNOTNULL,
  PRIMARY KEY ("MID")
);

Fails with :-

 Caused by: java.lang.IllegalStateException: Pre-packaged database has an invalid schema: viewLog(a.a.so67711264kotlinroomprepackageddb.ViewLogModel).
 Expected:
TableInfo{name='viewLog', columns={vid=Column{name='vid', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, mid=Column{name='mid', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, uts=Column{name='uts', type='REAL', affinity='4', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}
 Found:
TableInfo{name='viewLog', columns={VID=Column{name='VID', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, UTS=Column{name='UTS', type='real', affinity='4', notNull=true, primaryKeyPosition=0, defaultValue='null'}, MID=Column{name='MID', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}}, foreignKeys=[], indices=[]}

However, using a database who's DDL is:-

CREATETABLE "viewLog" (
  "mid" INTEGERNOTNULL,
  "uts" realNOTNULL,
  "vid" INTEGERNOTNULL,
  PRIMARY KEY ("mid")
)

works as expected.

So you either need to change the DDL as above or change the Entity to reflect the DDL e.g. the following works with the original (failed) DDL:-

@Entity(tableName = "viewLog")
data class ViewLogModel(
    @PrimaryKey val MID: Int,
    val VID: Int,
    val UTS: Float)

or alternately you could use @ColumnInfo's like:-

@Entity(tableName = "viewLog")
data class ViewLogModel(
    @PrimaryKey@ColumnInfo(name = "MID") val mid: Int,
    @ColumnInfo(name ="VID") val vid: Int,
    @ColumnInfo(name = "UTS") val uts: Float)

Post a Comment for "Pre-packaged Database Has An Invalid Schema Column Order"