SwiftData Tables disappearing while test my app!

I begin testing my IOS swiftdats Xcode 15 swift 5 on Sonoma and I am able to create my siwftdata tables as well as add records to several of the tables, Then as I proceeded with my te tables disappear and I get this error in the Xcode debug console: error: Error: Persistent History (6) has to be truncated due to the following entities being removed: ( AppSettings, Invoice, Clientele, Pay, InvoiceItem, TrackingArt ) This app used to work fine and as I was making changes it started behaving in this manner. Beside the code I will supply the entire debug console with the attached file

Here is how I have the swift data containers setup.

import SwiftData
import TipKit
import CloudKit

@main

 struct ArtManagerApp: App {
    
     @StateObject private var copyInvoiceDetails = CopyInvoiceDetails()
     @StateObject private var copyPaymentDetails = CopyPaymentDetails()
     @StateObject private var artTypeSettings = ArtTypeSettings()
     @StateObject private var tipManager = TipManager()
 //    @Query(sort: \ArtPiece.artPieceID, order: .forward) private var artPieces: [ArtPiece]
 //    @Query(sort: \AppSettings.setID, order: .reverse) private var settingsList: [AppSettings]
     
     var sharedModelContainer: ModelContainer = {
         let schema = Schema([
             ArtPiece.self, Clientele.self, TrackingArt.self, Invoice.self, InvoiceItem.self, AppSettings.self, Pay.self
         ])
         let modelConfiguration = ModelConfiguration(schema: schema,
                                                     isStoredInMemoryOnly: false)
         do {
             return try ModelContainer(for: schema, configurations: [modelConfiguration])
         } catch {
             fatalError("Could not create ModelContainer: \(error)")
         }
     }()

     var body: some Scene {
         
         WindowGroup {
             ContentView()
                 .navigationTitle("🎨 Art Manager")
                 .environmentObject(artTypeSettings)
                 .environmentObject(copyInvoiceDetails)
                 .environmentObject(copyPaymentDetails)
                 .environmentObject(tipManager) // Pass it to the ContentView
                 .modelContainer(sharedModelContainer)
         }
     }
    
 }
class TipManager: ObservableObject {
    @Published var tips: [ArtManagerTip] = []

    init() {
        loadTips()
    }

    func loadTips() {
        tips = [ArtManagerTips.search_tip, ArtManagerTips.delete_tip, ArtManagerTips.extendedSearch_tip,
                ArtManagerTips.searchPayments_tip, ArtManagerTips.searchArt_tip, ArtManagerTips.librarySearch_tip, ArtManagerTips.artMaintenanceSearch_tip]
    }
}

class CopyPaymentDetails: ObservableObject {
    @Published var payNumber: Int32 = 0
    @Published var payType: String = ""
    @Published var payPatronID: Int32 = 0
    @Published var payPatronName: String = ""
    @Published var payPatronAddress: String = ""
    @Published var payPaymentAmount: Double = 0.0
    @Published var payDatePayed: Date = Date()
}
class CopyInvoiceDetails: ObservableObject {
    @Published var invoiceNumber: Int32 = 0
    @Published var invoicePatronName: String = ""
    @Published var invoicePatronPO: String = ""
    @Published var invoiceDateCreated: Date = Date()
    @Published var artPieceIDSaved: [Int32] = []
}

    
Answered by DTS Engineer in 798263022

Xcode debug console: error: Error: Persistent History (6) has to be truncated due to the following entities being removed: ( AppSettings, Invoice, Clientele, Pay, InvoiceItem, TrackingArt )

This error indicates that you removed some models in the current version schema without doing migration. I discussed this topic in the other post. You can take a look if that helps.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I don't see where you used the @Model macro to change your classes into SwiftData. Did I miss something?

Xcode debug console: error: Error: Persistent History (6) has to be truncated due to the following entities being removed: ( AppSettings, Invoice, Clientele, Pay, InvoiceItem, TrackingArt )

This error indicates that you removed some models in the current version schema without doing migration. I discussed this topic in the other post. You can take a look if that helps.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Is there a way to start complete fresh? I have made some changes to one of the tables but I don't want to save any data so I can start like this is the first time I am running the app? I tried a couple of actions like removing the scheme and deleting the container from macOS Sonoma but the error persists?

Thanks

I may not completely understand what you are trying to achieve, but if you would like to completely remove an existing SwiftData store for an macOS app, consider using the following steps:

  1. Run your app and figure out the store URL by looking into ModelContainer.configurations and ModelConfiguration.url, and then stop running it.

  2. Remove your app.

  3. Use the store URL to find your store and remove it. A store contains multiple files, and you need to remove all of them.

  4. If your store is associated with a CloudKit database, use CloudKit Console to reset the CloudKit container.

For an iOS app, step 2 should remove the store, and so you can simply do step 2 and 4. If the store is on an app group container shared with another app and the app still exists on the device, step 2 doesn't remove the store, and so you need to use your code to remove the store programmatically.

You can then re-install your app and observe it works without any initial data.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

At this point I have a couple of questions. First one is regarding your first response. Were you saying some how swiftdata know I change one of the table models and I need to do a migration?

Secondly, I wanted to be able to to a clean build and have the app run as if it was the very first run, so I am thinking I need to delete any and all swiftdata persistent data. For now I am not using cloudkit. So, what you described in your second answer is how to do this?

So, I am trying to find the cause and a resolution for the tables being dropped Thanks

A few more points to add to this issue:

  1. I used another computer which had never been used for testing my app. macOS Sonoma as well as Xcode 15.4 was used. Same issue. To me this suggests I have some in the source or Xcode settings is causing this behavior.

  2. I changed my source to I changed this code to print the SwiftData containers etc.

  var sharedModelContainer: ModelContainer = {
         let schema = Schema([
             ArtPiece.self, Clientele.self, TrackingArt.self, Invoice.self, InvoiceItem.self, AppSettings.self, Pay.self
         ])
         let modelConfiguration = ModelConfiguration(schema: schema,
                                                     isStoredInMemoryOnly: false)
         do {
             let container = try ModelContainer(for: schema, configurations: [modelConfiguration])
             
             // Add print statements here
             print("ModelContainer:", container)
             print("Configurations:", container.configurations)
             print("Schema:", container.schema)
             
             return container
         } catch {
             fatalError("Could not create ModelContainer: \(error)")
         }
     }()

I see this line on the Xcode Debug Console url: file:///Users/bobsoule/Library/Containers/B43D6A46-213E-427E-ACE5-B7EE77071C0C/Data/Library/Application%20Support/default.store However I don't see this folder B43D6A46-213E-427E-ACE5-B7EE77071C0C in /Users/bobsoule/Library/Containers

  1. I have the issue on Xcode15 as well as Xcode 16 beta

  2. I have attached the Debug Console Log from this test.

  3. I am able to create and populate with data three of the tables before this issue arrises.

Accepted Answer

I went back to a July 10 version of my app and put most of the changes into this version, and now it works fine. So, I still don't know what I broke to cause this but I was in the process of migrating my app to swift6. At this point I am fine and will put off the migration to swift6 to the future.

SwiftData Tables disappearing while test my app!
 
 
Q