RealmError (Realm error : Cannot add object to Realm because the object is managed by another Realm instance)

I want to delete all user data and add a user to the collection but while executing .deleteAll() and then trying to add but facing this error Cannot add object to Realm because the object is managed by another Realm instance in Flutter.

Hi @Agnel_Selvan,

Where’s the user in the code snippet above coming from? If you’re copying or moving an object from one realm to another, you need to make a deep copy (i.e. copying not only the object itself, but the sub-objects it may contain or refer to), writing (or assigning) it to a different realm won’t work as Realm keeps “live” objects linked to the respective databases.