Did a successful Core Data migration but the existing store was deleted - core-data

I have a CoreData store managed with MagicalRecord. I did a successful migratiion, but lost the data in the newly created store. This is what I have:
salonbookV1.0 is the original xcdatamodel for the initial store. I added only new attributes to an existing entity, and the mappingmodel looks like this: (a partial image).
Let me elaborate on what I did...
created the xcdatamodeld folder with both xcdatamodel's in it
marked the salonbookV1.0 as the current version and ran the app creating some entries
stopped the app, and marked salonbookV1.5 as the current version and ran the app
data which was entered previously was gone! (apparently the migration did not occur)?
The migration was accomplished; I know that because I can use the new attributes. However, the existing CD store was deleted. I have read all I can on MR, and there is only one method that deals with migration; MR does the rest without any coding from me.
So the question remains: why is the existing store being deleted?

I don't know about MR but in "normal" Core Data you have to set the NSMigratePersistentStoresAutomaticallyOption to the persistent store, otherwise it will not migrate your existing data to the new store version.

Related

How to transfer data from old database to new modified database in django?

I have old django project and new django project. I created dump file from database of old django. And also I made changes in tables and created new tables.
Now I want to load that dump file to my new django app. I am facing errors when I firstly migrate then restore data or firstly restore then migrate..
When I do migration first, it says tables already exist.
When I do restore first , it says django.db.utils.ProgrammingError: relation "django_content_type" already exists
I use migrate --fake error goes but new tables are not created in database.
I spent 3-4 days but could not succeed.
Please, help me if you can.
PS: my database is postgresql
This is not straightforward and will need some manual interventions and it depends on what do you want to do in the future
If the tables that already exist in the database have a stable design and won't be changed or you can do the changes manually using SQL statements then set managed = False to the models' meta, this will make Django skip making migrations for those models
If you want to keep the power of migration in the new project for all models then this will more complex
Delete all your migrations
You need to make your models equivalent to your database, you can set managed=False for new models like Users
Run python manage.py makemigrations, this will create the structure of the initial database.
Fake running the migrations python manage.py migrate --fake
Dump the records of django_migrations table
Create a new empty migration (with --empty) and add the SQL statements of the django_migrations table to it using migrations.RunSQL()
now fake again so you skip that new migration.
Now you are ready to use migrations as usual.
When installing new database, you will just need to run python manage.py migrate

Coredata migration is really needed?

I have a SQLite database with two columns it is bundled in the app. There is no write or save interaction in the database, it is fixed and read only. I read some documents and tutorials about the lightweight/manual migration all make it clear that you have to save the user data when migrating, that is not my case I don't need to save user data, I will deploy a new app version with a new database. I want to add two new attributes to my database and use in the app. Why I have to migrate? Why can't I just delete the old three files of SQLite database and add the new one and use the new attributes as needed. So I tried and did not work, anyone here to give me the steps to make the app to recognize the new database?
Actually the way to delete the SQL database files is the right way.
But you have to do that before the Core Data stack is going to be initialized.

Service builder doesn't delete table in DB

Hi all,
I'm using LR 6.1.
I created a new entity Called " Recommendation" in service.xml then a run BuildServices with Ant to generate the service builder Files.
Now I want to delete the Entity. So I Deleted if from service.xml, but nothing happens in Data base and the other files: The Database Table is here and the other generates File.
any idea?
Thanks a lot.
Liferay will never ever delete a table which has been in your service.xml but is now deleted. Also it will not delete any of the classes generated by a build-service command. For example it could be the case, that you refactored your portlet to 2 different projects. On a deploy, you don't want to lose all your data, only because the table is now defined in a different service.xml. So don't see this as a bug, more a security feature. If you want to delete the table, you have to issue a drop command on your database, and manually delete the Service files generated by Liferay Service Builder.

Incompatible managed object model

I'v built the app, with a working datamodell with one entity. The managedObjectContext works fine with the arrayController, and a TableView. A pretty straightforward, and common setup.
There's almost no code yet, I'm just trying to play a bit with coredata.
The problem is, when I change the modell, for example add a new entity, it no longer compatible, end show two errors while loading the app.
here are the errors:
The managed object model version used to open the persistent store is
incompatible with the one that was used to create the persistent store.
Failed to initialize the store
I guess somehow it tries to load to last model to the array, but i'm not intrested in that. I want to use the new one, and get rid of everything else.
I search stackoverflow and google all around, so I've cleaned the build folder, cleaned the app, still not working. Those folders in Library or Library/Application for my app name does not exists.
How to solve the problem, and make the app to use the new DataModel?
You have to delete the store file (the actual sqlite store). It will be recreated in your AppDelegate when you start the app again.
If you are using the simulator, you can go into the documents folder and delete it yourself. (Complicated.)
You can set a flag in your program and delete the store if set to true. That is a good setup for testing, especially when your data set is not too large and if you do not need your entered data to persist across relaunches. (Recommended.)
You simply delete the app from the device / simulator. (Easiest.)

Some default objects of core data entities

Here I have some entities in core data, for example, "Account",
and I wish that, when user enter my app for the first time, there is some thing in Account,
to make it more clear, maybe I should say I want to give some default managed-objects for an entity so that they will be there when the app is just installed.
How can I achieve this?
Thanks a lot!
I have a similar requirement for an app I'm working on. I am using a sqlite persistence store for my data, so I basically want to pre-populate that table with the data for my default entities.
To do this, I have created a separate project in my Xcode workspace that shares the same data model with my app. In this separate project I write the code I need to insert entities into the table, and to store the file in a well-known place on my Mac.
Then, I copy the sqlite file that my initializer app has created into the resources directory for my "real" app. As part of the startup for that app, I wrote a small bit of code that copies the default DB from the resources to my app's documents folder if a copy doesn't already exist there.
The end result is this: I can run my initializer app to populate the default data as I need to. I then copy the file into my real app, so when the app is first run there is a default copy of that DB ready to go.

Resources