### 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_
}
    // Add the s to wal, remove LegacyScriptPubKeyMan, and cleanup txs and address book data
    if (!wal.ApplyMigrationData(*data, error)) {
        return false;
    }
    return true;
}
utilResult<MigrationResult> MigrateLegacyToDescriptor(const stdstring& wal_name, const SecureString& passphrase, WalContext& context)
{
    MigrationResult res;
    bilingual_str error;
    stdvector<bilingual_str> warnings;
    //  th is still loaded, unload it so that nothing else tries to use it while we're changing it
    if (auto wal = GetWal(context, wal_name)) {
        if (!RemoveWal(context, wal, /*load_on_st, warnings)) {
            return utilError{_("Unable to unload th before migrating")};
        }
        UnloadWal(stdmove(wal));
    }
    // Load th but only in the context of this function.
    // No signals should be connected nor should anything else be aware of this wal
    WalContext empty_context;
    empty_context.args = context.args;
    DatabaseOptions options;
    options.require_existing = true;
    DatabaseStatus status;
    stdunique_ptr<WalDatabase> database = MakeWalDatabase(wal_name, options, status, error);
    if (!database) {
        return utilError{Untranslated("Wal file verification failed.") + Untranslated(" ") + error};
    }