SQLite error code:11 / Failed Migration

My app is crashing for a user with the error `SQLite error code:11`


After a lot of poking around, it looks like their data base got corrupted during migration, as there are a bunch of extra files in the database folder.


They look like this :


.modelName.sqlite.migrationdestination_xxxxx-shm

.modelName.sqlite.migrationdestination_xxxxx-wal

.modelName.sqlite.migrationdestination_xxxxx


It has also created a bunch of `..modelName_SUPPORT_transsrc_xxxxx/EXTERNAL_DATA/xxxx` files that share similar names to the still exisitng files that are present in a non-corrupted database.


My questions :

1 ) What causes this to happen? My assumption is that the app was quit mid-migration.


2 ) After this happens, how can I safely fix it and re-start the migration to avoid data loss.