[英]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.