简体   繁体   English

android 房间数据库架构无效错误导致primaryKeyPosition

[英]android room database schema invalid error caused by primaryKeyPosition

I have a simple database with few tables.i have implemented room entities for tables.i'm getting this error and it's saying that my schema is invalid.but i found it very similar only difference is column order and primaryKeyPosition.我有一个带有几个表的简单数据库。我已经为表实现了房间实体。我收到这个错误,它说我的架构是无效的。但我发现它非常相似,唯一的区别是列顺序和 primaryKeyPosition。

error message(i have omitted the foreign keys as they are equal)错误消息(我省略了外键,因为它们相等)

Expected:

TableInfo{name='am',
 columns={name=Column{name='name', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
 symbol=Column{name='symbol', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
 a_number=Column{name='a_number', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'},
 a_id=Column{name='a_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}},


Found:

TableInfo{name='am',
 columns={symbol=Column{name='symbol', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
 name=Column{name='name', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'},
 a_number=Column{name='a_number', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1, defaultValue='null'},
 a_id=Column{name='a_id', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=2, defaultValue='null'}},

i have attached a image to clarify the difference我附上了一张图片来澄清差异

在此处输入图像描述

as you can see only differences are * 1st and 2nd table column order is different * primaryKeyPosition is different in last column如您所见,唯一的区别是*第一个和第二个表列顺序不同*最后一列中的primaryKeyPosition不同

my entity class我的实体 class

@Entity(tableName = "am",
        foreignKeys = {
                @ForeignKey(entity = ATypes.class,
                        parentColumns = "a_id",
                        childColumns = "a_id"),
        },
        indices = {@Index("a_id")}
)
public class Am {

    public String name;
    public String symbol;
    @PrimaryKey
    @ColumnInfo(name = "a_number")
    public int aNumber;

    @NonNull
    @ColumnInfo(name = "a_id")
    public Integer aId;

}

my question how can i change the column order or primaryKeyPosition in order to match expected schema.我的问题是如何更改列顺序或 primaryKeyPosition 以匹配预期的架构。

You are missing the index for your primary key!您缺少主键的索引!

If you are using Robolectric the problem may be caused by this issue https://github.com/robolectric/robolectric/issues/4209如果您使用的是 Robolectric,问题可能是由这个问题引起的https://github.com/robolectric/robolectric/issues/4209

I had the same issues and I solved it with https://github.com/guness/RobolectricSQLite我有同样的问题,我用https://github.com/guness/RobolectricSQLite解决了它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决预填充数据库上涉及“notNull”和“primaryKeyPosition”的 Room 无效架构错误? - How do I resolve a Room invalid schema error involving 'notNull' and 'primaryKeyPosition' on prepopulated database? Android Room 预打包数据库存在无效架构错误 - Android Room Pre-packaged database has an invalid schema error Android Room 给出错误“预打包的数据库具有无效的架构”但导出的架构是正确的 - Android Room giving error "Pre-packaged database has an invalid schema" but exported schema is correct Room 报错:预打包的数据库对 FTS 表的架构无效 - Room gives error: pre-packaged database has an invalid schema for FTS Table 在 Room 中实现一对多时,预打包数据库有一个无效的模式错误 - Pre-packaged database has an invalid schema Error, when implementing one-to-many in Room android 房间数据库返回错误的架构表 - android room database returns wrong schema table Room 数据库预打包数据库的架构无效 - Room database Pre-packaged database has an invalid schema 桌子上的房间异常:预打包的数据库具有无效的架构 - Room exception on table: Pre-packaged database has an invalid schema 如何为 Android Room 数据库指定数据库架构名称 - How to specify a database schema name for Android Room database Android房间架构关系 - Android room schema relation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM