java


RealmMigration erased every data in my realm


Today I changed my application realm schema, and so I implemented a Migration.
Inside the migration, I just needed to add a field, so I did:
if (oldVersion == 0) {
RealmObjectSchema class = schema.get("Class");
class.addField("addedField", boolean.class, null)
.transform(new RealmObjectSchema.Function() {
#Override
public void apply(DynamicRealmObject obj) {
obj.set("addedField", false);
}
});
oldVersion++;
}
But this erased everything in my realm, I got no more data.
This is not a problem as I'm still in dev phase. I did the migration instead of uninstalling/reinstalling the app just to learn how to implement a RealmMigration.
Did I do something wrong? Is it normal that I got everything erased? Did I need to add some more code?
I already read the documentation and had a look at the sample app. The code provided didn't got anything more.
Realm configuration:
Realm.init(this);
RealmConfiguration newConfig = new RealmConfiguration.Builder()
.name("myRealm.realm")
.schemaVersion(1)
.migration(new SchemaMigration())
.build();
And at least:
Realm realm = Realm.getInstance(newConfig);
EDIT:
I solved this by removing the name("myRealm.realm"). At the first installation I didn't use a RealmConfiguration so the name of the realm was: "default.realm". Thank you guys for your support and your answers!
Try do not pass null as a field attributes and use type specific setter (setBoolean) for transformation of DynamicRealmObject:
if (oldVersion == 0) {
RealmObjectSchema class = schema.get("Class");
class.addField("addedField", boolean.class)
.transform(new RealmObjectSchema.Function() {
#Override
public void apply(DynamicRealmObject obj) {
obj.setBoolean("addedField", false);
}
});
oldVersion++;
}

Related Links

How to read from files with Files.lines(…).forEach(…)?
return an array from a function in java android
Sorting SharedPreferences using TreeMap - Not sorting it correctly (Answered)
parsing JSONObject to custom class
Apache POI difference between cloning style and getting style
Hibernate error node to be traverse cannot be null
use of Static variable in mapreduce programs
How can I place a label on top of another label?
Moving element by KeyListener in Swing
Apache HTTP Client giving 503 Status code instead fo 200
Unable to bind form to object
Programming language for configuration
NullPointerException - RelativeLayout and Gradients
Changing the size of an ImageView when image clicked
WeakReference and StrongReference GC behavior
Issue with adding a JPanel onto another JPanel

Categories

HOME
clips
amazon-ec2
activiti
google-api-php-client
session
electron
yahoo-oauth
jsrender
packages
jgroups
wamp
synchronization
maude-system
metatrader4
quickbooks
collectd
google-cloud-spanner
windows-azure-storage
uitypeeditor
apache-metamodel
oracle-coherence
lucene.net
zapier
tokenize
errorlevel
css-animations
smb
traffic
greendao
elasticsearch-ruby
c++-amp
gsoap
contact-form
android-nestedscrollview
language-concepts
io-redirection
jquery-bootgrid
hilbert-curve
unoconv
midl
logfiles
komodoedit
fancybox-2
statsd
darcs
jxcore
knockout-components
pearson
color-profile
blacklist
pintos
messenger
firmata
deadbolt-2
grails-tomcat-plugin
android-textview
pcf
transmitfile
connect-by
fadeout
oauth2client
maven-tomcat-plugin
r-tree
endeca-workbench
apache-commons-fileupload
python-green
tween
kgdb
transcoding
didselectrowatindexpath
balanced-payments
app42
algebraic-data-types
ivyde
tidy
runtime.exec
buster.js
pushbackinputstream
lcs
robotics-studio
referrer
cisco-jtapi
datawindow
onsubmit
netdna-api
inotifycollectionchanged
imac
html-input
google-friend-connect
digest-authentication
gin
bespin
zune
geneva-server

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile