### 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_
m_database = stdmove(new_db);
    // Write existing records into the new DB
    batch = m_database->MakeBatch();
    bool began = batch->TxnBegin();
    assert(began); // This is a critical error, the new db could not be written to. The original db exists as a backup, but we should not continue execution.
    for (const auto& [key, value]  records) {
        if (!batch->Write(Span{key}, Span{value})) {
            batch->TxnAbort();
            m_database->Close();
            fsremove(m_database->Filename());
            assert( // This is a critical error, the new db could not be written to. The original db exists as a backup, but we should not continue execution.
        }
    }
    bool committed = batch->TxnCommit();
    assert(committed); // This is a critical error, the new db could not be written to. The original db exists as a backup, but we should not continue execution.
    return true;
}
stdoptional<MigrationData> CWalGetDescriptorsForLegacy(bilingual_str& error) const
{
    AssertLockHeld(cs_wal);
    LegacyScriptPubKeyMan* legacy_spkm = GetLegacyScriptPubKeyMan();
    assert(legacy_spkm);
    stdoptional<MigrationData> res = legacy_spkm->MigrateToDescriptor();
    if (res == stdnullopt) {
        error = _("Error Unable to produce s for this legacy wal. Make sure to provide th's passphrase if it is encrypted.");
        return stdnullopt;
    }
    return res;
}
bool CWalApplyMigrationData(MigrationData& data, bilingual_str& error)