sqlite 文件室数据库预打包数据库的模式无效

qmelpv7a  于 2022-12-29  发布在  SQLite
关注(0)|答案(3)|浏览(196)

我有一个预打包房间数据库的问题。我有一个数据库发现外部存储。我已经复制了这个数据库放置在数据库目录。复制数据库后,我应该使用房间数据库,但不幸的是,java.lang.IllegalStateException Pre-packaged database has an invalid schema抛出。

    • 预期:**
TableInfo{name='glyphs', columns={max_x=Column{name='max_x', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, glyph_id=Column{name='glyph_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, page_number=Column{name='page_number', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, max_y=Column{name='max_y', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, line_number=Column{name='line_number', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sura_number=Column{name='sura_number', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, ayah_number=Column{name='ayah_number', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, min_x=Column{name='min_x', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, position=Column{name='position', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, min_y=Column{name='min_y', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[]}
    • 发现日期:**
TableInfo{name='glyphs', columns={max_x=Column{name='max_x', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, glyph_id=Column{name='glyph_id', type='int', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'}, page_number=Column{name='page_number', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, max_y=Column{name='max_y', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, line_number=Column{name='line_number', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, sura_number=Column{name='sura_number', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, ayah_number=Column{name='ayah_number', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, min_x=Column{name='min_x', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, position=Column{name='position', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, min_y=Column{name='min_y', type='int', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}}, foreignKeys=[], indices=[Index{name='sura_ayah_idx', unique=false, columns=[sura_number, ayah_number]}, Index{name='page_idx', unique=false, columns=[page_number]}]}

有什么能帮忙的吗?

klsxnrf1

klsxnrf11#

看起来您的导出没有Room支持的列类型。从您共享的架构来看,Room需要INTEGER而不是'int'。您应该尝试并坚持使用SQLite所需的数据类型,如下所述:https://www.sqlite.org/datatype3.html

6psbrbz9

6psbrbz92#

我发现了问题,方案的索引丢失了,我已经在@Entity类中添加了索引,它工作正常。
数据库中的索引用于加快查询速度,有关详细信息,请查看官方文档
房间数据库中的索引示例

@Entity(indices = arrayOf(Index(value = ["last_name", "address"])))
data class User(
    @PrimaryKey val id: Int,
    val firstName: String?,
    val address: String?,
    @ColumnInfo(name = "last_name") val lastName: String?,
    @Ignore val picture: Bitmap?
)
fhity93d

fhity93d3#

请记住在更正架构后重新安装应用程序

相关问题