This blog post helped in fixing it. Running sp_helpdb <dbname> showed that the owner field was NULL. Probably because the old dbowner was removed from Security Logins of the SQL Server.
I ran the following and the issue was fixed.
use <dbname> go sp_changedbownder @loginame = 'sa' go
(Although I’m not really sure why Microsoft decided to spell loginame that way.)