Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary Key issues...but I'm not using primary key in Model. #4777

Closed
sirvon opened this issue Mar 27, 2017 · 3 comments
Closed

Primary Key issues...but I'm not using primary key in Model. #4777

sirvon opened this issue Mar 27, 2017 · 3 comments
Labels

Comments

@sirvon
Copy link

sirvon commented Mar 27, 2017

We LOVE to help with any issues or bugs you have!

Questions: If you have questions about how to use Realm, ask on
StackOverflow.
We monitor the realm tag.

Feature Request: Just fill in the first two sections below.

Bugs: To help you as fast as possible with an issue please describe your issue
and the steps you have taken to reproduce it in as many details as possible.

Thanks for helping us help you! :-)

Please remove this line and all above before submitting.

Goals

What do you want to achieve?

Expected Results

What did you expected to happen?
I expected to be able to open the realm file.
I created the realm using realm-browser from a csv file

Actual Results

What did happened instead?

2017-03-26 17:16:56.542721 Mobile[490:246750] *** Terminating 
app due to uncaught exception 'RLMException', reason: 
'Only 'string' and 'int' properties can be designated the primary key'

Steps to Reproduce

class Destination: Object{

    
    //destinationSlackChannelName,destinationSlackChannelId,destinationName,destinationType,destinationCode,destinationRegionCode,destinationSiteSlackChannelName,destinationCity,destinationCountry,siteStatus,siteLastUpdated,lat,lng
    
    
    dynamic var destinationSlackChannelName = ""
    dynamic var destinationSlackChannelId = ""
    dynamic var destinationName = ""
    dynamic var destinationType = ""
    dynamic var destinationCode = ""
    dynamic var destinationRegionCode = ""
    dynamic var destinationSiteSlackChannelName = ""
    dynamic var destinationCity = ""
    dynamic var destinationCountry = ""
    dynamic var destinationStatus = ""
    dynamic var destinationLastUpdated = ""
    dynamic var lat:Double = 0.0
    dynamic var lng:Double = 0.0
    
}
    func getHebronDestinations() -> Results<DestinationREALM> {
        Log.info?.message("\(Realm.Configuration.defaultConfiguration.fileURL!)")
        let bundleUrl = Bundle.main.url(forResource: "default", withExtension: "realm")
        let config = Realm.Configuration(
            fileURL: bundleUrl,
            readOnly: true,
            schemaVersion: 0,
            migrationBlock: { migration, oldSchemaVersion in
                if (oldSchemaVersion < 1) {
                    Log.info?.message("\(oldSchemaVersion)")
                    Log.info?.message("wtf")
                }
                if (oldSchemaVersion < 2) {
                    Log.info?.message("\(oldSchemaVersion)")
                }
                Log.info?.message("Realm migration did run")  // Log to know migration was executed
            }
        )
        
        let realm = try! Realm(configuration: config)
        let naoHebronResults = realm
            .objects(DestinationREALM.self)
            .filter("destinationRegionCode == 'nao' AND destinationCode == 'heb'")
        Log.info?.message("\(naoHebronResults)")
        for res in naoHebronResults{
            Log.info?.message(res.destinationName)
        }
        return naoHebronResults
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        print("viewDidLoad")
        let realmManager = RealmManager.shared
        let hebDevices = realmManager.getHebronDestinations()
        print(hebDevices)
    }

Code Sample

Provide a code sample or test case that highlights the issue.
If relevant, include your model definitions.
For larger code samples, links to external gists/repositories are preferred.
Alternatively share confidentially via mail to help@realm.io.
Full Xcode projects that we can compile ourselves are ideal!

Version of Realm and Tooling

In the CONTRIBUTING guidelines, you will find a script,
which will help determining these versions.

Realm version: latest

Xcode version: latest

iOS/OSX version: latest

Dependency manager + version: carthage latest

@bdash
Copy link
Contributor

bdash commented Mar 27, 2017

The error message suggests that you have a primaryKey() method on one of your Object subclasses that's returning the name of a property whose type is not Int or String. Can you do a search in your project for a function named primaryKey to see if you've overlooked one?

@sirvon
Copy link
Author

sirvon commented Mar 27, 2017

found it!....i had a primary key on models I wasn't even using yet...models that wasnt even in the realm file.

@jpsim
Copy link
Contributor

jpsim commented Mar 27, 2017

All models you've defined are in the Realm file unless you explicitly specify a subset of the schema to use by setting Realm.Configuration.objectTypes.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants