I have a project that is using core data , i need add more attributes(Columns) to existing entity (Column) , if i manually add attribute to data model app crash and it is due t
If you are only adding attributes to an entity, you can use the automated lightweight migration in Core Data.
Basically all you have to do is pass an NSDictionary
instance with the appropriate options when you're adding the persistent store. Here's a code snippet from the end of an accessor method for _persistentStoreCoordinator
:
NSNumber *optionYes = [NSNumber numberWithBool:YES];
NSDictionary *options = [NSDictionary dictionaryWithObjects:@[optionYes] forKeys:@[NSMigratePersistentStoresAutomaticallyOption]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Error opening persistent store: %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
If your migration is too complex for a lightweight migration, you'll see an error. Otherwise the migration should run and your database will be updated to match your new schema.
Note that if you're doing this for real on a device, you should back up your .sqlite file first, in case something goes wrong in migration.