我们当前在应用程序内部使用Realm,但是当我尝试执行迁移时(因为我们要删除数据库中的Model / class),Configuration从configuration.schemaVersion
返回一些随机的巨大值。
不调用迁移,也不会删除任何内容。 let realm = try? Realm(configuration: Realm.compactConfiguration)
我试图在整个应用程序中进行一个配置,并将其设置如下:
let configuration = Realm.compactingConfiguration
Realm.Configuration.defaultConfiguration = configuration
但是仍然会出现大的schemaVersion,并且代码不会进入migrationBlock内部
extension Realm {
public static var compactConfiguration: Configuration {
get {
// Realm is compacted on the first open if the configuration block conditions were met.
// Compacting when size is greater than 50MB (arbitrary amount, database size should be
// around 2.6MB, so should not reach 50MB)
let currentSchemaVersion: UInt64 = 1
var configuration = Realm.Configuration(
schemaVersion: 1,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < currentSchemaVersion) {
migration.deleteData(forType: Office.className())
}
})
configuration.deleteRealmIfMigrationNeeded = true
return configuration
}
}
}
有人知道发生了什么吗?我希望versionScheme为0,因为它从未设置过。