【问题标题】:ReActiveAndroid - Database info referenced not foundReActiveAndroid - 未找到引用的数据库信息
【发布时间】:2018-07-01 15:48:29
【问题描述】:

我想用ReActiveAndroid替换旧的数据库代码但是所有操作都有错误

如文档中所述,我有这些类:

数据库类

@Database(name = "MyDatabase", version = 1)
public class MyDatabase {
}

应用类

DatabaseConfig appDatabase = new DatabaseConfig.Builder(MyDatabase.class)
            .build();

ReActiveAndroid.init(new ReActiveConfig.Builder(this)
            .addDatabaseConfigs(appDatabase)
            .build());

模型类

@Table(database = MyDatabase.class)
public class User extends Model {
    ...
}

插入代码

User user = new User();
user.id = id;
user.name = name;
user.save();

我有这个错误:

java.lang.IllegalArgumentException:未找到表 ir.hatamiarash.app.models.User 引用的数据库信息

有没有我遗漏的设置?

【问题讨论】:

  • 遇到同样的问题,你解决了吗?
  • @nasch 这是一个旧库,我无法解决这个问题...尝试使用另一个类似 Realm 的库。

标签: android database orm android-sqlite activeandroid


【解决方案1】:

没错,但我选择 ReactiveAndroid 的原因是从 ActiveAndroid 迁移。 Realm 不使用 SQLite,这意味着迁移过程会更加复杂。

我找到了解决这个问题的方法:

DatabaseConfig appDatabase = new DatabaseConfig.Builder(AppDatabase.class) .addModelClasses(LogEntry.class) .addMigrations(AppDatabase.MIGRATION_16_17) .build();

您必须致电addModelClasses。还有一些文档有助于解决随后出现的错误:https://imangazalievm.gitbooks.io/reactiveandroid/migration-from-activeandroid.html

【讨论】:

    猜你喜欢
    • 2018-04-09
    • 2017-03-02
    • 2014-01-01
    • 1970-01-01
    • 2020-06-19
    • 2015-11-01
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    相关资源
    最近更新 更多