我正在尝试构建一个非常简单的数据库来存储Hangman游戏的分数。
我建立了一个实体:
@Entity(tableName="scores"(数据类DBScore(@PrimaryKeyvar伪:字符串="&";,var得分:Int=0({
}
//从DB模型到kotlin模型乐趣的转换方法List.asDomainModel((:列表{回波图{得分(pseudo=it.pseudo,score=it.score)}
}
用数据库文件用样本值预填充数据库
INSTANCE = databaseBuilder( context.applicationContext, AppDataBase::class.java, "app_database" ) .createFromAsset("database/scores.db").build()
为此,我创建了以下数据库文件:https://wetransfer.com/downloads/c534dd62136c94f17c0ee71f1ef39a1920201011144837/6ff2b7
但我遇到了一个错误,不明白我的数据库有什么问题:
引起原因:java.lang.IllegalStateException:预打包的数据库具有无效的架构:scores(com.example.hangmangame.database.entity.DBScore(。预期:TableInfo{name='score',columns={pseudo=Column{name='seudo',type='TEXT',affinity='2',notNull=true,primaryKeyPosition=1,defaultValue='ull'},score=Column{name='core',type='NTEGER',affinity='3',notNull=true,primaryKeyPosition=0,defaultValue='ull'}},foreignKeys=[],indexes=[]}找到:TableInfo{name='scores',columns={score=Column{name='core',type='NTEGER',affinity='3',notNull=false,primaryKeyPosition=0,defaultValue='ull'},pseudo=Column{name='seudo',type='EXT',affility='2',notNull=true,primaryKeyPosition=1,defaultValue='ull'}}},foreignKeys=[],indexes=[]}
列的顺序似乎有问题,但对我来说SQL对此并不敏感
谢谢你的帮助。
问候
昆汀。
Room期望score
为NOT NULL
。显然,根据错误,您预先填充的数据库模式将其设置为NULL
。