Realm-java: Remove a table from a previous Realm scheme

Created on 12 Aug 2015  ·  11Comments  ·  Source: realm/realm-java

Hi,
With the introduction of Modules (Realm 0.82.0), I have splitted a part of my scheme into another Realm.
However, the old database (which is now a core Module) still contains tables that are no longer needed (and data as well).

Example:
Old scheme contained A, B, C into main.realm.
New scheme is now splitted in two Modules
A, B into main.realm
C into second.realm

Following the app update, main.realm still contains a table C and I'm unable to clean nor delete the table manually (error like 'this entity is not part of this module').

Is there a way I did not find?
Thanks.

T-Bug

Most helpful comment

@kkmike999 You can use realm.getSchema().remove(className). https://realm.io/docs/java/latest/api/io/realm/RealmSchema.html#remove-java.lang.String-

All 11 comments

Hi @tmeunier
Thanks for reporting this. It seems you are correct. The current realm.getTable() method actually checks if your table is part of the schema, which makes it hard to delete tables. That is clearly a bug as you should be able to manipulate tables not part of the Schema.

Our new migration API will also fix this: https://github.com/realm/realm-java/pull/1239

Thanks @cmelchior
I look forward to this new migration API, the current one is very limited and I cannot just drop the database on new version :)

You really need removeClass() in our upcoming migration API. I can't give you a release date but we are working on it.

i agree with @kneth @tmeunier . we need an API such like sql DROP TABLE

@kkmike999 You can use realm.getSchema().remove(className). https://realm.io/docs/java/latest/api/io/realm/RealmSchema.html#remove-java.lang.String-

Thanks to the new Migration API and RealmSchema this is now possible @kkmike999 ;)

@cmelchior when i call Realm realm = Realm.getInstance(config); realm.getSchema().remove("User"); realm.copyToRealmOrUpdate(user), then throw java.lang.IllegalArgumentException: A RealmObject with no @PrimaryKey cannot be updated: class com.example.realm.bean.User T_T

public class User extends RealmObject {
    @PrimaryKey
    public int    uid;
    @Required
    public String name;

        //  getter and setter
}

Hi @kkmike999 Can you please create a new issue for that? That will make it easier for us to track it and help you.

@cmelchior i've ask my question in http://stackoverflow.com/questions/36416685/how-to-change-table-name-in-realm-android

thx for answering my question

@kkmike999 An answer has been provided at SO.

@kneth i'm sorry bother you again, the answer in SO is not the way solving the problem that i want. i created issue https://github.com/realm/realm-java/issues/2555

Was this page helpful?
0 / 5 - 0 ratings