### 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_
{
        LOCK(g_wal_release_mutex);
        auto it = g_unloading_wal_set.insert(name);
        assert(it.second);
    }
    
    
    
    wal->NotifyUnload();
    
    wal.reset();
    {
        WAIT_LOCK(g_wal_release_mutex, lock);
        while (g_unloading_wal_set.count(name) == 1) {
            g_wal_release_cv.wait(lock);
        }
    }
}
 {
stdshared_ptr<CWal> LoadWalInternal(WalContext& context, const stdstring& name, stdoptional<bool> load_on_start, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, stdvector<bilingual_str>& warnings)
{
    try {
        stdunique_ptr<WalDatabase> database = MakeWalDatabase(name, options, status, error);
        if (!database) {
            error = Untranslated("Wal file verification failed.") + Untranslated(" ") + error;
            return nullptr;
        }
        context.chain->initMessage(_("Loading wal…").translated);
        stdshared_ptr<CWal> wal = CWalCreate(context, name, stdmove(database), options.create_flags, error, warnings);
        if (!wal) {