Vlad Morzhanov
Vlad Morzhanov

Reputation: 1298

Realm Object is not part of the schema for this Realm

I'm using realm as database for my app and i have model SessionModel:

public class SessionModel extends RealmObject {

    private long id;

    private int currentPomod;

    private int state;

    ...getters\setters
}

When i'm trying to create new document in database:

Realm.init(this);

realm = Realm.getDefaultInstance();

realm.beginTransaction();
realm.copyToRealm(defSession);

I got this error: java.lang.IllegalArgumentException: SessionModel is not part of the schema for this Realm

My top level gradle file contains this dependencies:

...
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'

    classpath "io.realm:realm-gradle-plugin:2.3.0"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
...

and app gradle module applying this plugins (ont top of build.gradle module app file):

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

...

Instant Run disabled.

Upvotes: 2

Views: 3805

Answers (3)

CodeAndWave
CodeAndWave

Reputation: 1604

Encountered this error just now. I tried rearranging my plugins still didnt work. Turns out since I am using a managed realmList now for automatic update, I have to change the realm config as well on the application. just delete your current realm. using this Realm.deleteRealm(realmConfig); then start again but just comment the code out.

Upvotes: 0

Ajeet Singh
Ajeet Singh

Reputation: 2009

Found some solution from git issues. Its looking like same problem you have.

Solution: apply apply plugin: 'com.neenbedankt.android-apt' before apply plugin: 'realm-android'

Hope it will help you!!

Upvotes: 0

wilddev
wilddev

Reputation: 1974

In my case it was the following situation: MyClass was implementing RealmModel, but was not annotated with @RealmClass

Upvotes: 1

Related Questions