Realm React Native - Migration is required: Target type 'string' doesn't exist for property 'emailAddresses'

允我心安 提交于 2019-12-12 17:37:06

问题


I am building a small app with React Native and want to use Realm for persistency.

I defined the following schema for a Person:

const personSchema = {
  name: 'Person',
  properties: {
    familyName: {type: 'string', optional: true},
    givenName: {type: 'string'},
    middleName: {type: 'string', optional: true},
    emailAddresses: {type: 'list', objectType: 'string'},
  }
}
export class Person {}
Person.schema = personSchema

The information as to how a Realm schema needs to be defined can be found in the Realm docs.

I then instantiate the DB like so:

const schemas = [Person]
const db = new Realm({schema: schemas})

However, there is an exception when reaching the last line giving me the following error:

Unhandled JS Exception: Migration is required due to the following errors:

  • Target type string doesn't exist for property emailAddresses.

I am using the iOS simulator for testing and deleted the app several times and then reinstalled it using the play button in Xcode.

Does anyone have an idea why I am getting this exception?

Update

I now created a separate schema for another db object: EmailAdress

const emailAddressSchema = {
  name: 'EmailAddress',
  properties: {
    label: 'string',
    email: 'string'
  }
}
export class EmailAddress {}
EmailAddress.schema = emailAddressSchema

I also changed the objectType of emailAddresses in the personSchema to be of type EmailAddress now:

...
emailAddresses: {type: 'list', objectType: 'EmailAddress'},
...

Now, I am not getting the exception any more. Isn't it possible to add a property to a Realm class that is a list of strings?


回答1:


Lists of primitives are not yet supported in Realm. Until they are you need to wrap primitive types in an object as you have done with EmailAddress



来源:https://stackoverflow.com/questions/36516924/realm-react-native-migration-is-required-target-type-string-doesnt-exist-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!