I have added new array attribute to the RLMObject and
public class Student: RLMObject {
dynamic var id = 0
dynamic var name = ""
dynamic var resultList = RLMArray(objectClassName:Result.className())
}
public class Result: RLMObject {
}
ERROR Log:
Migration is required for object type 'Student' due to the following errors: - Property 'resultList' has been added to latest object model.
TRY Failed:
let configuration:RLMRealmConfiguration = RLMRealmConfiguration.defaultConfiguration()
migration.enumerateObjects(Student.className()) { oldObject, newObject in
newObject!["resultList"] = RLMArray(objectClassName: Result.className())
}
EDIT:
let configuration:RLMRealmConfiguration = RLMRealmConfiguration.defaultConfiguration()
print("Realm db current version: \(configuration.schemaVersion)")
configuration.schemaVersion = 1
configuration.migrationBlock = {(migration:RLMMigration, oldSchemaVersion: UInt64) in
print("Realm db migration start")
if oldSchemaVersion < 1 {
print("Schema version: 1 - Rename fields")
migration.enumerateObjects(Student.className()) { oldObject, newObject in
newObject!["creationDate"] = oldObject!["createdAt"]
newObject!["modifiedDate"] = oldObject!["updatedAt"]
}
}
print("Realm db migration finish")
}
RLMRealmConfiguration.setDefaultConfiguration(configuration)
let realm = RLMRealm.defaultRealm()
SOLUTION:
update your version to +1
configuration.schemaVersion += 1
You have to incremented your schemaVersion
and provide a migrationBlock
on your RLMRealmConfiguration
. In there you can migrate tables. But you don't need that in your specific case here. The addition of properties can be handled automatically. You'll still need an empty block.
let config = RLMRealmConfiguration.defaultConfiguration()
config.schemaVersion = 1
config.migrationBlock = { (migration, oldSchemaVersion) in
// nothing to do
}
RLMRealmConfiguration.setDefaultConfiguration(config)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With