### 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_
if (!spk_man->SetupGeneration()) {
                            error = Untranslated("Unable to generate initial keys");
                            status = DatabaseStatusFAILED_CREATE;
                            return nullptr;
                        }
                    }
                }
            }
            // R
            wal->Lock();
        }
    }
    NotifyWalLoaded(context, wal);
    AddWal(context, wal);
    wal->postInitProcess();
    // W
    UpdateWalSetting(*context.chain, name, load_on_start, warnings);
    // L
    if (!(wal_creation_flags & WALLET_FLAG_DESCRIPTORS)) {
        warnings.push_back(_("Wal created successfully. The legacy wal type is being deprecated and support for creating and opening legacy wals will be removed in the future."));
    }
    status = DatabaseStatusSUCCESS;
    return wal;
}
stdshared_ptr<CWal> RestoreWal(WalContext& context, const fspath& backup_file, const stdstring& wal_name, stdoptional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, stdvector<bilingual_str>& warnings)
{
    DatabaseOptions options;
    ReadDatabaseArgs(*context.args, options);
    options.require_existing = true;
    const fspath wal_path = fsbridgeAbsPathJoin(GetWalDir(), fsu8path(wal_name));