realm-js: Default value doesn't apply for newRealm migrations, all fields are required.
Goals
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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (8 by maintainers)
@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.
Yeah I don’t know what it was. I’m on iOS. The only thing I can think of since the tests look fine is that maybe I left
async
in the migration function. I was testing both default values and async, so that could’ve been it. Going to close this one out for now.