.RecreateStoreOnModelMismatch does not work #79

Closed
opened 2025-12-29 15:23:48 +01:00 by adam · 9 comments
Owner

Originally created by @TechMaster on GitHub (Sep 10, 2016).

I found that .RecreateStoreOnModelMismatch does not work. When I configured storage, then added new entity to CoreData model, then I found error.

I also tried with demo source code in github and encounter same problem.
"The model used to open the store is incompatible with the one used to create the store"

func configureStorage() {
        _ = dataStack.addStorage(
            SQLiteStore(
                fileName: "HumanResource.sql",
                configuration: "Default",
                localStorageOptions: .RecreateStoreOnModelMismatch)
            ,
            completion: { (result) in
                switch result {
                case .Success(let storage):
                    print("Successfully added sqlite store: \(storage)")
                case .Failure(let error):
                    print("Failed adding sqlite store with error: \(error)")
                }
        })

        CoreStore.defaultStack = dataStack
    }
Originally created by @TechMaster on GitHub (Sep 10, 2016). I found that .RecreateStoreOnModelMismatch does not work. When I configured storage, then added new entity to CoreData model, then I found error. I also tried with demo source code in github and encounter same problem. **"The model used to open the store is incompatible with the one used to create the store"** ``` func configureStorage() { _ = dataStack.addStorage( SQLiteStore( fileName: "HumanResource.sql", configuration: "Default", localStorageOptions: .RecreateStoreOnModelMismatch) , completion: { (result) in switch result { case .Success(let storage): print("Successfully added sqlite store: \(storage)") case .Failure(let error): print("Failed adding sqlite store with error: \(error)") } }) CoreStore.defaultStack = dataStack } ```
adam added the fixedcorestore bug labels 2025-12-29 15:23:48 +01:00
adam closed this issue 2025-12-29 15:23:48 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Sep 10, 2016):

Can you reproduce this on iOS 8? I feel this is due to iOS 9's persistent store model caching.

@JohnEstropia commented on GitHub (Sep 10, 2016): Can you reproduce this on iOS 8? I feel this is due to iOS 9's persistent store model caching.
Author
Owner

@TechMaster commented on GitHub (Sep 10, 2016):

I am downloading iOS 8 simulator now. But CoreStore crashes in iOS 9 when developer change model : adding new entity, modify new attribute.

Is there any option to turn off iOS 9's persistent store model caching?

@TechMaster commented on GitHub (Sep 10, 2016): I am downloading iOS 8 simulator now. But CoreStore crashes in iOS 9 when developer change model : adding new entity, modify new attribute. Is there any option to turn off iOS 9's persistent store model caching?
Author
Owner

@JohnEstropia commented on GitHub (Sep 10, 2016):

Not that I've seen yet. I'll see if there's a way to work around it. Thanks for the report!

@JohnEstropia commented on GitHub (Sep 10, 2016): Not that I've seen yet. I'll see if there's a way to work around it. Thanks for the report!
Author
Owner

@TechMaster commented on GitHub (Sep 10, 2016):

Hi John,

I simulate on iOS 8.4 encounter sample problem. I made a simple project so you can easily reproduce bug at your side in 5'.

Please pull code at https://github.com/TechMaster/SimpleCoreStore

Failed adding sqlite store with error: (CoreStore.CoreStoreError) .InternalError (
    ._domain = "com.corestore.error";
    ._code = 4;
    .NSError = (
        .domain = "NSCocoaErrorDomain";
        .code = 134100;
        .userInfo = 2 key-value(s) [
            metadata = {
                NSPersistenceFrameworkVersion = 519;
                NSStoreModelVersionHashes =     {
                    Person = <544bdb3f f98a282c 25e330bc 09ddc378 9f7c0e58 8398b647 087395fe 3439653f>;
                };
                NSStoreModelVersionHashesVersion = 3;
                NSStoreModelVersionIdentifiers =     (
                    ""
                );
                NSStoreType = SQLite;
                NSStoreUUID = "23B367CD-45F8-498F-9397-6BB1D418956E";
                "_NSAutoVacuumLevel" = 2;
            };
            reason = The model used to open the store is incompatible with the one used to create the store;
        ];
    );
)
@TechMaster commented on GitHub (Sep 10, 2016): Hi John, I simulate on iOS 8.4 encounter sample problem. I made a simple project so you can easily reproduce bug at your side in 5'. Please pull code at https://github.com/TechMaster/SimpleCoreStore ``` Failed adding sqlite store with error: (CoreStore.CoreStoreError) .InternalError ( ._domain = "com.corestore.error"; ._code = 4; .NSError = ( .domain = "NSCocoaErrorDomain"; .code = 134100; .userInfo = 2 key-value(s) [ metadata = { NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { Person = <544bdb3f f98a282c 25e330bc 09ddc378 9f7c0e58 8398b647 087395fe 3439653f>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "23B367CD-45F8-498F-9397-6BB1D418956E"; "_NSAutoVacuumLevel" = 2; }; reason = The model used to open the store is incompatible with the one used to create the store; ]; ); ) ```
Author
Owner

@JohnEstropia commented on GitHub (Sep 10, 2016):

Thank you for your report. I'm afraid I can't reproduce this If I don't have your old xcdatamodeld. You can check that with your app too, if you delete and reinstall your app you won't see this error again (until the next time you change the model). But the cause of this problem is clear so I'll try look for a fix.

@JohnEstropia commented on GitHub (Sep 10, 2016): Thank you for your report. I'm afraid I can't reproduce this If I don't have your old xcdatamodeld. You can check that with your app too, if you delete and reinstall your app you won't see this error again (until the next time you change the model). But the cause of this problem is clear so I'll try look for a fix.
Author
Owner

@TechMaster commented on GitHub (Sep 10, 2016):

To reproduce error, you just create a new entity in model, you will see error immediately.

For the moment, I work around by deleting the app when model is changed. I think that .RecreateStoreOnModelMismatch does not delete model file.

@TechMaster commented on GitHub (Sep 10, 2016): To reproduce error, you just create a new entity in model, you will see error immediately. For the moment, I work around by deleting the app when model is changed. I think that .RecreateStoreOnModelMismatch does not delete model file.
Author
Owner

@JohnEstropia commented on GitHub (Sep 11, 2016):

@TechMaster Please try out the fix I pushed to the develop branch. If it fixes the problem for you I'll push it to a Cocoapods update

@JohnEstropia commented on GitHub (Sep 11, 2016): @TechMaster Please try out the fix I pushed to the `develop` branch. If it fixes the problem for you I'll push it to a Cocoapods update
Author
Owner

@TechMaster commented on GitHub (Sep 11, 2016):

Hi John,

It works perfectly !
I pull your latest source code from develop branch, copy all files, folders in Sources folder then paste to folder Pods\CoreStore\Sources. I compiled and made change to model. The app did not crash any more, it delete old model and copy new compile model.

You can push new code to Cocoapods now. After you push, please let me now, i will test again.

Thanks

@TechMaster commented on GitHub (Sep 11, 2016): Hi John, It works perfectly ! I pull your latest source code from develop branch, copy all files, folders in Sources folder then paste to folder Pods\CoreStore\Sources. I compiled and made change to model. The app did not crash any more, it delete old model and copy new compile model. You can push new code to Cocoapods now. After you push, please let me now, i will test again. Thanks
Author
Owner

@JohnEstropia commented on GitHub (Sep 11, 2016):

Fixed in version 2.0.6. Thanks again!

@JohnEstropia commented on GitHub (Sep 11, 2016): Fixed in version 2.0.6. Thanks again!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#79