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 8928925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:33:38+00:00 2026-06-15T08:33:38+00:00

I am getting this nasty crash and error. The crash occurs when this code

  • 0

I am getting this nasty crash and error.

The crash occurs when this code runs:

    Address *address = [[Address alloc] initWithEntity:[NSEntityDescription entityForName:@"Address" inManagedObjectContext:managedObjectContext] insertIntoManagedObjectContext:nil];

        //Crashes here!
        [person addAddressObject:address];

Illegal attempt to establish a relationship 'person' between objects in different contexts

The entire console error is below.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Illegal attempt to establish a relationship 'person' between objects in different contexts (source = <Address: 0x1f87e270> (entity: Address; id: 0x1f87e2b0 <x-coredata:///Address/t748EE284-0311-4489-9654-1D902EB0D4CC2> ; data: {
    addressLine1 = "";
    addressLine2 = "";
    addressLine3 = "";
    city = "";
    country = "";
    person = nil;
    state = "";
    title = "";
    zip = "";
}) , destination = <Person: 0x1ed9e1e0> (entity: Person; id: 0x1ed9c710 <x-coredata://ED0283A9-A847-407E-BFEC-CF2BF85C6A9C/Person/p1> ; data: {
    address =     (
        "0x1f87e2b0 <x-coredata:///Address/t748EE284-0311-4489-9654-1D902EB0D4CC2>",
        "0x1ed93e70 <x-coredata://ED0283A9-A847-407E-BFEC-CF2BF85C6A9C/Address/p1>"
    );
    favourite = nil;
    firstName = Josh;
    lastName = Kahane;
}))'

I have no clue how to fix this. Presumably it thinks there is two different managedObjectContexts? However, in my app I only ever reference that made in my app delegate like so (run at viewDidLoad):

if (managedObjectContext == nil)
    {
        managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
        NSLog(@"After managedObjectContext: %@",  managedObjectContext);
    }

Any ideas as to where to start looking for the discrepancies? Thanks.

EDIT:

New discovery. Just before the app crashes, I’ve NSLogged both the address and person managed object contexts. Turns out the address context is (null), even if I run the check right before hand to set the context if its nil.

  • 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-06-15T08:33:40+00:00Added an answer on June 15, 2026 at 8:33 am

    You’re inserting it into a nil managedObjectContext.

    You’ll need to insert the object into the NSManagedObjectContext that you use for the entity. i.e. managedObjectContext.

    In the alloc init of the Address object.

    Reading your comment in the OP.

    You should either…

    Save all the required values and then at the point on confirmation create the Address object and insert it all in one go.

    Or…

    Create the object and insert it creating all the relationships and then if the user presses cancel just delete the object.

    I’d do one of these two to avoid this error.

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

Sidebar

Related Questions

Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I'm getting this nasty error during compression through uglyfier. But it hell of a
Getting this error when I follow the simple code example from jsoncpp, that basically
Getting this error while compiling C++ code: undefined reference to `__stack_chk_fail' Options already tried:
Getting this error with my fetch's predicate 2011-08-13 13:49:12.405 Codes[16957:10d03] NSlog Array: code BETWEEN
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Getting this error when try to add an item to my repositories/context: Collection has
Am getting this error message and matched my brackets and couldn't find anything wrong.
I´m getting this error while trying to commit to a svn repository: svn: MKACTIVITY

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.