Reinstalling wordpress from database breaks the site

Here is how I fixed it:
Toms comment made me check how I could migrate the database URL without accessing the admin panel. Turns out it’s really easy. Go to phpMyAdmin and into your wp database. Go into the wp_options table and the first row should be the site url. Change it to the correct site (and subfolder). From then I could log into the admin panel and change permalinks and so on.

Thank you Tom!