2016-08-25 79 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);