2016-08-25 77 views
1

我将迁移添加到了我的项目中。经过很多工作后,我将其独立运行。尝试更新时出现错误如何设置可空区域对象

@PrimaryKey field 'id' does not support null values in the existing Realm file. Migrate using RealmObjectSchema.setNullable(), or mark the field as @Required 

这不适用于我添加的对象中的值特征。任何人都可以详细说明这一点或链接到文档如何做到这一点?我找不到任何

这是可变

@PrimaryKey 
private String id; 

编辑:愿做

schema.get("Log").setNullable("id", true); 

回答

2

那么,如果你已经更新了旧的代码库,那么你已经解决了它'breaking change from 0.89.0其中@PrimaryKey注释字段变为空(​​并且null可用作1个元素的主键)。

因此,如果您不希望@PrimaryKey带注释的字段为空,则应该只添加@Required注释。

否则,您应该添加到您的迁移:

RealmObjectSchema yourClassSchema = schema.get("YourClass"); 
yourClassSchema.setNullable("id", true);