Update:
Visual Studio 2022 ships with Microsoft SQL Server 2019 15.0.4153.1 LocalDB
. If you have Visual Studio 2022 installed but have previously used an earlier version of Visual Studio you can jump to the command sqllocaldb versions
below to upgrade.
https://developercommunity.visualstudio.com/t/visual-studio-2022-installs-old-version-of-sql-ser/1466986
Original:
This is what I did since Visual Studio 2019 still ships with Microsoft SQL Server 2016 (13.1.4001.0) LocalDB
.
I needed to do it because I tried to add Temporal tables
with cascading delete that failed.
https://learn.microsoft.com/en-us/sql/relational-databases/tables/temporal-tables?view=sql-server-ver15
Failed executing DbCommand (31ms) [Parameters=[], CommandType='Text',
CommandTimeout='30'] ALTER TABLE Text SET (SYSTEM_VERSIONING = ON
(HISTORY_TABLE = History.Text));
Setting SYSTEM_VERSIONING to ON failed because table
'Project.Repository.dbo.Text' has a FOREIGN KEY with cascading DELETE
or UPDATE.
Reading up on it it turns out this error only affects SQL Server 2016 and not 2017 and later.
ON DELETE CASCADE and ON UPDATE CASCADE are not permitted on the
current table. In other words, when temporal table is referencing
table in the foreign key relationship (corresponding to
parent_object_id in sys.foreign_keys) CASCADE options are not allowed.
To work around this limitation, use application logic or after
triggers to maintain consistency on delete in primary key table
(corresponding to referenced_object_id in sys.foreign_keys). If
primary key table is temporal and referencing table is non-temporal,
there's no such limitation.
This limitation applies to SQL Server 2016 only. CASCADE options are
supported in SQL Database and SQL Server 2017 starting from CTP 2.0.
https://stackoverflow.com/a/54591579/3850405
https://learn.microsoft.com/en-us/sql/relational-databases/tables/temporal-table-considerations-and-limitations?view=sql-server-2017

You can get information about your current localDBs by running the command sqllocaldb info
in Powershell.
This is quite a good upgrading guide but I choose to do some things a bit differently.
https://medium.com/cloudnimble/upgrade-visual-studio-2019s-localdb-to-sql-2019-da9da71c8ed6
Download SQL Server Express 2019 LocalDB
or newer and run the exe.
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15
Select Download Media:

LocalDB:

Install from the downloaded exe:

My recommendation is to restart your computer after this but I'm not sure it is needed. I did it anyway.
Checking sqllocaldb versions
caused the exception Windows API call "RegGetValueW" returned error code: 0.
for me.

Solved it using this answer:
https://stackoverflow.com/a/58275480/3850405
This is how Registry Editor
(regedit) looks like in the non working example:

After changing the folder name everything works:


After this back up databases in your current localdb. This will probably not be needed since we will attach all databases from your current localdb to the new version later but if you have sensitive data this is recommended.
I have the standard name MSSQLLocalDB
from Visual Studio so my example will use this. As mentioned before you can use sqllocaldb info
command to view your current versions.
Run these three commands from powershell:
sqllocaldb stop mssqllocaldb
sqllocaldb delete mssqllocaldb
sqllocaldb create MSSQLLocalDB
If everything works the last command should generate something like LocalDB instance "mssqllocaldb" created with version 15.0.2000.5.

Then log into your new LocalDB via SSMS (localdb)\mssqllocaldb
or a similar program and attach your old databases. Usually stored in the %UserProfile%
folder.

LocalDB is now updated and hopefully all your databases works normally.