I had the same issue (same error on heroku, working on local machine) and I tried all the solutions listed here including
heroku run rails console
which ran without error messages. I tried heroku run rake db:migrate
and heroku run rake db:migrate:reset
a few times. None of this solved the problem. On going through some files that are used in production but not in dev environment, I found some whitespace in the puma.rb file to be the culprit. Hope this helps someone who has the same issue.
Changing this made it work
ActiveRecord::Base.establish_connection
End
to
ActiveRecord::Base.establish_connection
end