It’s sometimes useful to have multiple realms, persisted at different locations, for example if you have different data groupings, different databases per feature, or you need to package some read-only files with your app, separate from the database your users will be editing.
Unfortunately this is not true, at least it does not work for me. I have added 2 databases to raw resources and both databases have one different class in them:
database 1: classA
database 2: classB
I the copy these databases to a writable folder but when I want to open database1 it says that classB is missing and if I open database 2 it says classA is missing. So what is the point in having 2 databases if you still have to have all the tables used in the app in each one of them?
I checked the Migration project here:
but it does not apply to my case since I have not changed the tables at all I just want 2 separate databases with 2 separate classes in each one of them.
Would there be anyway I could keep my 2 separate databases (I don't need to write in them, only read)?
I know I could just have both tables in one file but before doing that I wanted to make sure there was no other way.
Here are the steps I use for each one of the databases:
1. copy database from raw folder to context.getFilesDir()/databaseYYY.realm
2. get database with this.realm2 = Realm.getInstance(context, "databaseYYY.realm");
On the getInstance line I get the following exception:
io.realm.exceptions.RealmMigrationNeededException: The ClassA class is missing from the schema for this Realm.
After reading the source code I realized that you are looking for all the classes that extend RealmObject so there is no way the statement written above can work, unless I am missing something.
For now I only see 2 possibilities: having only one database with both classes or insert missing table in each one of the databases.
Any suggestions?
Thanks in advance,
--
You received this message because you are subscribed to the Google Groups "Realm Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-java+...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-java/169e99c4-5a6a-4dba-9695-356a5f10ca6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Christian,
Thank you very much for such a quick reply. Although the example you
provides seems to fulfill my requirements unfortunately I was not able to
try it.
I tried adding the snapshot dependency, the latest one in Frog
Yes, copying the database should work also across Android/iOS. We will take a look at your Stack Overflow question.
--
Christian Melchior
Senior Android Developer