Swift Realm Deleted Schema is causing Sync Error

Hey I have to schemas Person and Personal with object IDs. Previosly I had an Schema Users without an _id. Since deleting Users I expect I should be able to sync realm on the swift client. But I keep getting this error:

Error Domain=io.realm Code=1 "Schema validation failed due to the following errors:

- There must be a primary key property named ‘_id’ on a synchronized Realm but none was found for type ‘User’" UserInfo={Error Name=SchemaValidationFailed, NSLocalizedDescription=Schema validation failed due to the following errors:

- There must be a primary key property named ‘_id’ on a synchronized Realm but none was found for type ‘User’, Error Code=1}

What I have tried:

  1. Restarting Sync
  2. Deleting the app from my phone and restarting my phone
  3. Check Schema in MongoDB and make sure it matches.

Please let me know if anyone has ideas!

It sounds like your a Realm file still has Users in it - or - the code still has a Users object defined. Try opening the Realm file with the Realm Studio app and deleting any existing User objects.

You can also try adding your User object back into the code as an object but include a _id primary key. Since it’s additive it should just add it. Once done, you will then be able to remove the object.

Lastly, you could just delete the local Realm file totally and let it rebuild the next time it sync’s.