Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7547785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:32:30+00:00 2026-05-30T09:32:30+00:00

I have two persistent stores with objects that use the same model. I would

  • 0

I have two persistent stores with objects that use the same model. I would like to open both stores in one context, but save the context to only a single store, and then safely delete one of the stores. I am in essence trying to merge the contents of two persistent stores into a single persistent store. Because the entities have relationships, I am finding this difficult.

From this answer:

If you do need to have relationships between the objects in both stores, or you really just want to have a single store, your best bet would be to create a second NSPersistentStoreCoordinator and a third, distinct persistent store to hold the merged object graph. You will need to write code to create copies of the objects in a managed object context attached to this second NSPersistentStoreCoordinator. You’ll need to set up the same relationships among the copies that the original objects had, too, but how you go about doing this depends on your data model.

That makes it seem clear, except for the details of how, literally, to make copies of the objects for the new store. Is this a migration issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:32:31+00:00Added an answer on May 30, 2026 at 9:32 am

    Ultimately, I used the following approach:

    [migrator migrateStoreFromURL:[NSURL fileURLWithPath:incomingPath]
                             type:nil 
                          options:nil 
                 withMappingModel:managedObjectModel 
                 toDestinationURL:[NSURL fileURLWithPath:finalPath] 
                  destinationType:nil 
               destinationOptions:nil 
                            error:&err];
    
    [persistentStoreCoordinator removePersistentStore:[[persistentStoreCoordinator persistentStores]lastObject] error:&err];
    

    The file at “incomingPath” was the store I imported, the file at “finalPath” the already-existent store that I wanted to merge into. Both stores were open in the same persistent coordinator, and both use the same object model. I then removed the incoming store and never looked at it again; I suppose I could have deleted it at the file system level.

    For my particular data needs, I then fetched all the records, culled out the duplicates, and saved the context.

    I publish this answer because as a core data newbie this simple migration solved the “can’t save relationships to objects in different stores” problem non-intuitively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a core data model that has two entities which have a
I'm currently developing an app that uses Core Data. I'm using two stores/configurations, one
I've the following problem: I have two or more persistent stores. And I have
I have a persistent class Author with two fields: int id , String name
I have two applications written in Java that communicate with each other using XML
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two classes, and want to include a static instance of one class
I have two threads, one needs to poll a bunch of separate static resources
I have two spreadsheets... when one gets modified in a certain way I want
I'm currently upgrading an older iPhone flashcard application that uses two SQLite dbs (one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.