executeFetchRequest:error: A fetch request must have an entity
Solution 1
It seemed as if my data got corrupted, so I deleted my data model and the database in the iPhone simulator, and started fresh.
Solution 2
My issue is I didn't use the same name for Entity and Class. Trivial solution to fix it is by giving them the same name.
Solution 3
If you are using MagicalRecored
with Swift
:
Make sure you use @objc
directive in the Swift NSManagedObject
subclass to make the class accessible to Objective-C code from the MagicalRecord library
@objc(MyEntity)
class MyEntity: NSManagedObject {
@NSManaged var myAttribute: Int16
}
Solution 4
After searching all over for a solution, what fixed it for me was doing a Clean/Build in Xcode.
Product->Clean, Product->Build, then try running it.
Solution 5
I had the same error.
For me, it is because I have added a new Model Version, but I did not set it as "Current Version". Careless me! To fix, select the xcdatamodel, click Design > Data Model > Set Current Version. The xcdatamodel file will then have a green tick.
Hopes that helps.
sudo rm -rf
Hi, I'm Jonathan. I'm an iOS & Mac developer with a specialty in Core Animation. I created this Stack Overflow account back when I knew absolutely nothing about programming. Thus this profile serves as a documentation of my journey to where I am today. Glad I was able to help people out along the way. Keep up with me elsewhere: GitHub: https://github.com/jwilling Twitter. https://twitter.com/willing Blog: http://jwilling.com
Updated on August 16, 2020Comments
-
sudo rm -rf over 3 years
I had a project that was working fine. It had "Core Data" checked, and had the data model all set up. I only started adding a couple entities and properties tonight. When I try to run my app now, it won't even load. It just crashes on me.
Here's the error:
'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'
I'm really scared because I don't have a backup of this and if I can't get it working I don't know what I'll do. :)
Thanks in advance!
EDIT: I got fed up with my data, so I just copied a new blank xcdatamodel to my project and I'm going to start fresh. Thanks for the help!
-
Nuthatch about 11 yearsyeah, don't forget to delete the app from the simulator!
-
Jay Imerman about 11 yearsI both deleted the app in the Simulator, and did Clean/Build. Same problem, so this did not fix the issue for me. I do not want to delete and recreate a complex data model. So, how to correct the issue non-destructively?
-
Jake Stoeffler about 11 yearsWhy the down-vote, @JayImerman? I'm sorry that my answer didn't work for you, but that doesn't mean you should down-vote it. Did you try a "Reset Content and Settings" in the simulator? Does it work on a real device?
-
apb about 9 yearsThanks! The entity file will get overwritten anytime you recreate the NSManagedObject subclass though. Is there a better way to do it than manually adding that line each time?
-
gaussblurinc over 8 yearsis it a trivial solution? You can simply modify Default configuration (mapping: entity -> class) in data model.
-
Afzaal Ahmad almost 7 yearsapp crash in iOS 9.3 but working with iOS 10.3 when i add @objc(MyEntity) as suggested it work on iOS 9.3 but app crash on iOS 10.3 any idea why it crash?
-
Roman over 4 yearsOr let fetchRequest: NSFetchRequest<ReminderData> = fetchRequest() with no need to type a name of the entity explicitly (by using that function which you mentioned in Codegen file ReminderData+CoreDataProperties.swift)
-
amin torabi over 3 yearsit says Aug 15, 2020