Delete corrupt database and perform a fresh setup
See original GitHub issueImagine for some reason we lose our encrypted database key (see Android KeyStore issue) and as a fallback we want to send the user to our app’s registration process. There, the app workflow will be restarted and our Realm database would have to be deleted and set up again.
As we’re not able to delete Realm using deleteAll()
API method (lost key), we could remove Realm database file from the file system getting it’s path previously.
Once I send the app to the registration process, I set up the new database with it’s new configuration:
realmConfiguration =
new RealmConfiguration.Builder()
.encryptionKey(newEncryptionKey)
.directory(realmFile)
.deleteRealmIfMigrationNeeded()
.build();
In this step I get two behaviors:
- If the database key is matches the previous one, I get a “class_xxxxxx has no primary key defined” error.
- Instead, if the database key is different and fresh one, I get the “Wrong key used to decrypt Realm.” error.
How could I solve this problem?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How to manually delete a corrupted database instance
I have a corrupted instance in my database which prevents me from starting up the other instances.
Read more >How Do I Fix MySQL Server Database Corruption Smoothly
Step 1: Download, install and launch Stellar Repair for MySQL software. Step 2: In Select Data Folder window, select the MySQL version you...
Read more >How to delete a corrupt database from azure sql
1 Answer 1 · Once you are logged in, set read/write · In serach box find your resource · Click actions (POST/DELETE) //...
Read more >Windows Update Database Corruption - Microsoft Community
Windows Update Database Corruption · Run Command Prompt as Administrator · Stop BITS, Cryptographic, MSI Installer and Windows Update Services. To ...
Read more >How to Rebuild a Database with a Corrupted or Deleted SQL ...
The log cannot be rebuilt because there were open transactions/users when the database was shutdown, no checkpoint occurred to the database, or ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@XabierGoros I don’t think we have ever considered this case - thanks for bringing it up 😃
Currently solution is either to manually delete the Realm file or use a different name.
Long term solution is that we add a
deleteRealmIfWrongEncryptionKey()
option toRealmConfiguration
.@Zhuinden I’m basically storing all Realm data in a custom folder, and erasing the whole folder which should be similar to the code above except it is performed by
RealmCache
(not accessible outside):