Post

Replies

Boosts

Views

Activity

Reply to Random "duplicate column name" crashes using SwiftData
I had the exact same problem. On the first startup everything is ok, then on the second one it crashes. It seems SwiftData doesn't see the already existing column for one-to-many relationship. This, in turn, crashes the application because of the duplicated column. The solution that I found is to explicitly create the inverse relationship in the second model. So, in your case, changing your DeskPosition model to this: @Model final class DeskPosition { let id: UUID var title: String var desk: Desk? private var heightInCm: Double @Transient var height: DeskHeight { get { DeskHeight(value: heightInCm, unit: .centimeters).localized } set { heightInCm = newValue.converted(to: .centimeters).value } } init(id: UUID, height: DeskHeight, title: String) { self.id = id self.heightInCm = height.converted(to: .centimeters).value self.title = title self.height = height } }
Oct ’23