簡體   English   中英

Android Realm Schema不匹配錯誤

[英]Android Realm Schema mismatch error

你們如何將Java領域對象與Swift領域對象進行匹配?

我的領域開發始於Swift,因此對象服務器包含從swift遷移的數據。 然后,我使用Java(帶有Realm Studio中的模型)創建了android版本。

Swift:
class OrderItem: Object {
    @objc dynamic var id: String = ""
}

Java
public class OrderItem extends RealmObject {
//    @PrimaryKey
    private String id;
}

Error without @PrimaryKey:
Bad changeset received: Schema mismatch: 'OrderItem' has a primary key on one side, but not on the other.

Error with @PrimaryKey: 
Exception has been thrown: The following changes cannot be made in additive-only schema mode: Primary Key for class 'OrderItem' has been added.

任何想法如何解決這些錯誤?

沒有@PrimaryKey的錯誤:收到錯誤的變更集:模式不匹配:'OrderItem'的一側有主鍵,而另一側則沒有。

這表明架構不匹配將執行破壞性的架構操作,因此不正確。

@PrimaryKey錯誤:引發了異常:在僅加法模式下無法進行以下更改:已添加類“ OrderItem”的主鍵。

這意味着您可能事先沒有使用@PrimaryKey嘗試,因此您在本地仍具有不具有主鍵的架構,因此您需要擦除應用程序的數據以刪除Realm文件,然后使用@PrimaryKey再次嘗試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM