question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default value doesn't apply for newRealm migrations, all fields are required.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
knethcommented, Jul 5, 2019

@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.

1reaction
knethcommented, Jun 26, 2019

@jaltin I have created a small test in #2424. I hope to have a fix soon.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found