Default value doesn't apply for newRealm migrations, all fields are required.
See original GitHub issueGoals
To be able create new objects without specifying fields with default values during migration.
Expected Results
New objects created.
Actual Results
Error: http://localhost:8083/call_method net::ERR_EMPTY_RESPONSE
Steps to Reproduce
Create model with a default value and try to create new object from it during migration without using the default fields.
Code Sample
const CarSchema = {
name: 'Car',
properties: {
make: 'string',
model: 'string',
miles: {type: 'int', default: 0},
}
};
// will break
{
schema: [CarSchema],
schemaVersion: 1,
migration: (oldRealm, newRealm) => {
newRealm.create("CarSchema", {
make: "lambo",
model: "murcy"
});
}
}
// will succeed
{
schema: [CarSchema],
schemaVersion: 1,
migration: (oldRealm, newRealm) => {
newRealm.create("CarSchema", {
make: "lambo",
model: "murcy",
miles: 0
});
}
}
Version of Realm and Tooling
- Realm JS SDK Version: 2.1.1
- Node or React Native: react-native
- Client OS & Version: chrome 63
- Which debugger for React Native: chrome
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Use default values for new properties in Realm migration
Now I expected that after the migration each old User object would have a new useImages property already set to true (the default...
Read more >Adding a new required field to an existing schema and client
I am trying to create add a new required field to an existing realm sync schema. Everything seems to work fine when adding...
Read more >Migration with Realm (RealmSwift Part 6) | by Ali Akhtar
As documented “Note that default property values aren't applied to new objects or new properties on existing objects during migrations. We ...
Read more >Upgrading Guide - Keycloak
New Admin Console is now the default console; Changes to the ... Manual migration step needed; Upgrade to Wildfly 23; Upgrade to Wildfly...
Read more >Ultimate Guide to Realm Database Migration in Android
Whenever we add or remove property in the existing Realm class or create a new Realm class, we need to increase the schema...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@myself379 Yes, you update your schema and increment the version. The version is stored in the Realm file, so when you open a file at a lower schema version, the migration is triggered.
@jaltin I have created a small test in #2424. I hope to have a fix soon.