### Is there an existing issue for this?

- [X] I have searched the existing issues

### Current behaviour

crash

### Expected behaviour

no crash

### Steps to reproduce

* Compile 79e8247ddb166f9b980f40249b7372a502402a4d
* Type `migratewallet`

### Relevant log output

```
wallet/scriptpubkeyman.cpp:1915: std::optional<MigrationData> wallet::LegacyScriptPubKeyMan::MigrateToDescriptor(): Assertion `IsMine(desc_spk) != ISMINE_NO' failed.
Aborted (core dumped)
```


### How did you obtain Bitcoin Core

Compiled from source

### What version of Bitcoin Core are you using?

current master

### Operating system and version

Linux

### Machine specifications

_No response_
}
        }
        // First change to using SQLite
        if (!local_wal->MigrateToSQLite(error)) return utilError{error};
        // Do the migration, and cleanup if it fails
        success = DoMigration(*local_wal, context, error, res);
    }
    if (success) {
        // Migration successful, unload th locally, then reload it.
        assert(local_wal.use_count() == 1);
        local_wal.reset();
        LoadWal(context, wal_name, /*load_on_st, options, status, error, warnings);
        res.wal_name = wal_name;
    } else {
        // Migration failed, cleanup
        // Copy the backup to the actual wal dir
        fspath temp_backup_location = fsbridgeAbsPathJoin(GetWalDir(), backup_filename);
        fscopy_file(backup_path, temp_backup_location, fscopy_optionsnone);
        // Remember this wal's waldir to remove after unloading
        stdvector<fspath> wal_dirs;
        wal_dirs.push_back(fsPathFromString(local_wal->GetDatabase().Filename()).parent_path());
        // Unload th locally
        assert(local_wal.use_count() == 1);
        local_wal.reset();
        // Make list of wals to cleanup
        stdvector<stdshared_ptr<CWal>> created_wals;
        if (res.watchonly_wal) created_wals.push_back(stdmove(res.watchonly_wal));
        if (res.solvables_wal) created_wals.push_back(stdmove(res.solvables_wal));
        // Get the directories to remove after unloading
        for (stdshared_ptr<CWal>& w  created_wals) {