此Realm的架构中缺少该类 [英] The class is missing from the schema for this Realm

查看:427
本文介绍了此Realm的架构中缺少该类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • Android studio 2.3.3

  • Realm 3.5.0

public RealmController(Context context) {
    try {
        this.context = context;
        Realm.init(context);
        PrintLog("RealmController", "RealmController", "Init realm", LOG_LEVEL_INFO);
        realmInstance = Realm.getDefaultInstance();
        PrintLog("RealmController", "RealmController", "Getting realm instance", LOG_LEVEL_INFO);
    }
    catch (Exception err) {
        PrintLog("RealmController", "RealmController", "Error: " + err.getMessage(), LOG_LEVEL_ERROR);
    }
}



SellingData.java



SellingData.java

public class SellingDataTable extends RealmObject {

    public Date todaysDate;
    public int sellingData;

    public Date getTodaysDate() {
        return todaysDate;
    }
    public void setTodaysDate(Date todaysDate) {
        this.todaysDate = todaysDate;
    }
    public int getSellingData() {
        return sellingData;
    }
    public void setSellingData(int sellingData) {
        this.sellingData = sellingData;
    }
}



预期行为




  • 获取领域默认实例。

  • 会崩溃。

    08-09 15:24:16.044 [I2maxMain] {Init} (preparing ui)
    08-09 15:24:16.120 [RealmController] {RealmController} (Init realm)
    08-09 15:24:16.129 [RealmController] {RealmController} (Error: The 'SellingDataTable' class is missing from the schema for this Realm.)
    


    推荐答案

    如果您在设备上创建具有给定架构的Realm,那么如果您开始修改架构(通过添加新类,添加新字段,删除字段,添加/删除 @Index ,添加/删除 @Required ,更改类型等等)然后您需要提供迁移(例如这里),或者你需要指定 deleteIfMigrationNeeded()

    If you create a Realm with a given schema on the device, then if you start modifying the schema (by adding new classes, adding new fields, removing fields, adding/removing @Index, adding/removing @Required, changing a type, etc.) then you either need to provide a migration (example here), or you need to specify deleteIfMigrationNeeded() on your RealmConfiguration.

    这篇关于此Realm的架构中缺少该类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆