我剛剛爲我的Realm模型添加了主鍵,因此我一直收到以下錯誤。我試圖在appdelegate中遷移,但仍然得到了錯誤。我所做的只是添加propertyKey()
功能。我如何正確遷移?在Realm中遷移主鍵
Migration is required for object type 'Organization' due to the following errors:
- Property 'id' has been made a primary key."
但是我已經低於媒體鏈接添加的appdelegate:
Realm.Configuration.defaultConfiguration = Realm.Configuration(
schemaVersion: 1,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < 1) {
// The enumerate(_:_:) method iterates
// over every Person object stored in the Realm file
migration.enumerate(Organization.className()) { oldObject, newObject in
// combine name fields into a single field
}
}
})
這裏是我的對象
class Location: Object {
var id: Int = 0
var longitude: Double = 0
var latitude: Double = 0
override class func primaryKey() -> String {
return "id"
}
}
class Organization: Object {
var id: Int = 0
var name: String = ""
var image: NSData = NSData()
let locations = List<Location>()
override class func primaryKey() -> String {
return "id"
}
}
所以它會是newObject![「primaryKeyProperty」] = 0(或任何其他int) –