mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
How to add property into existing model #220
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shift00 on GitHub (Jun 28, 2018).
Hello, I need help 🆘
I have CoreStore without *.xcdatamodel files. It's working fine, but when I added new property to my model app returns crash from CS.
I know that this is a configuration error, but I have no idea what to change to make it work.
Initialization code looks like this:
CoreStore.defaultStack = dataStackI changed modelVersion from V1 to V2, but this solution not working 😢
I think the topic is trivial, but I could not find the answer in the documentation.
@JohnEstropia commented on GitHub (Jun 28, 2018):
You'll need to keep both V1 and V2 entities and add them both to your
DataStack. CoreStore needs to know all your old models as well as your latest model for it to infer migrations.See https://github.com/JohnEstropia/CoreStore#declaring-model-versions, especially the section CoreStoreSchema-based model versions with progressive migration.
@shift00 commented on GitHub (Jun 28, 2018):
@JohnEstropia, thanks for your fast reply.
Ok, I have DataStack with two CoreStoreSchemas (I love github code formatting...)
next, I have:
CoreStore.defaultStack = dataStackand this magic writed with documentation:
And this solution not working 😞 where did I make a mistake?
@JohnEstropia commented on GitHub (Jun 28, 2018):
@shift00 Can you try this again without the
configuration: "Config2"argument? If you aren't using that feature you can just passnil.@shift00 commented on GitHub (Jun 28, 2018):
@JohnEstropia Nope, it still does not work. The code from the success/failure case section does not call.
@JohnEstropia commented on GitHub (Jun 28, 2018):
Are you working on freshly migrated data or are you running this after you got the
❗ [CoreStore: Fatal Error]?Your previous code and your new code have totally different entity names for the V1 classes. The V1 entities should be exactly the same as your old one.
(also fixed your code formatting 😄 )
@shift00 commented on GitHub (Jun 28, 2018):
I carried out two tests
first: remove installed app from device -> install fresh instance of my app - working 👍
second: remove installed app from device -> install fresh instance of old version app (without V2 and changes for migration) -> working -> install instance of new version app (with new mechanism and V2 models) - not working 👎
It is possible that
addStoragewill not update models in the database if it exists?@JohnEstropia commented on GitHub (Jun 29, 2018):
We have multiple projects that use this migration feature without issues.
Do you set the
VersionLockfor your V1 models? When you run your app's old version, check the console logs for the VersionLock and take note of the hashes for each entity. (See https://github.com/JohnEstropia/CoreStore#versionlocks)Once you have the hashes for your old version, you can try your app's new version again adding the versionLock for V1 as a parameter to
CoreStoreSchema. You will know if you accidentally edited your V1 because CoreStore will check the hashes beforehand.@shift00 commented on GitHub (Jun 29, 2018):
Unfortunately, the
VersionLockdoes not return any errors in the V1 model 😭 I am sure that to solve the problem, just change one line. I do not know where yet 😆@lqmios commented on GitHub (Dec 26, 2019):
@shift00 I had the same problem,Have you solved your problem?