I've started developing app with SwiftData and decided to move to VersionedSchema recently and it just fails when I try to add a new version of a schema with Code=134504 "Cannot use staged migration with an unknown coordinator model version."
When I initially added version and named it v1, all worked fine, but making any changes to future schemas bring the same error. (right now I'm on V2, but I just dropped data on my development devices).
import Foundation
import SwiftData
enum SchemaV2: VersionedSchema {
static var versionIdentifier: Schema.Version = Schema.Version(2, 0, 0)
static var models: [any PersistentModel.Type] {
[..., cardModel.self]
}
...other models...
@Model
final class cardModel {
var bank: bankModel
var name: String?
init(bank: bankModel, name: String? = nil) {
self.bank = bank
self.name = name
}
}
}
SchemaV3:
import Foundation
import SwiftData
enum SchemaV3: VersionedSchema {
static var versionIdentifier: Schema.Version = Schema.Version(3, 0, 0)
static var models: [any PersistentModel.Type] {
[..., cardModel.self]
}
...other models...
@Model
final class cardModel {
var bank: bankModel
var name: String?
var rewardType: RewardType?
init(bank: bankModel,
name: String? = nil,
rewardType: RewardType? = .cash
) {
self.bank = bank
self.name = name
self.rewardType = rewardType
}
}
}
MigrationPlan:
import SwiftData
enum MigrationPlan: SchemaMigrationPlan {
static var stages: [MigrationStage] {
[
MigrateV1toV2, MigrateV2toV3
]
}
static var schemas: [any VersionedSchema.Type] {
[SchemaV1.self, SchemaV2.self, SchemaV3.self
]
}
static let MigrateV1toV2 = MigrationStage.lightweight(
fromVersion: SchemaV1.self,
toVersion: SchemaV2.self
)
// I want to use a custom migration here, but even lightweight fails
static let MigrateV2toV3 = MigrationStage.lightweight(
fromVersion: SchemaV2.self,
toVersion: SchemaV3.self)
}
Not too sure how can I proceed, since I have versionIdentifier in every schema and they are semver. Clean builds, Mac reload, beta Xcode were tried as well with no luck. Searching for unknown coordinator model version didn't help much.
p.s.I initialise SchemaV1 like this:
enum SchemaV1: VersionedSchema {
static var versionIdentifier = Schema.Version(1, 0, 0) // Also tried to use such form with no luck: public static var versionIdentifier: Schema.Version {.init(1, 0, 0)}
static var models: [any PersistentModel.Type] {
[..., cardModel.self]
}
...models...
}