So somewhere you changed the postgres port to 50432 instead of 5432? (OR maybe the migration code does that and I’ve never noticed).
Maybe switch to the postgres13 template as suggested in the OP? And if that works, what I would do is move to a new server and avoid the whole transition-to-new-postgres-version issue and just restore the database to the new server.