Search code examples
ruby-on-railsherokudatabase-migrationheroku-postgresruby-on-rails-8

Heroku not running database migrations for Rails app


I have a Rails 8 app deployed to Heroku. The app was working with the Postgres database connected. I pushed code for an automatic deploy. The deploy said it worked, but I am getting a 500 on some pages that reference the table I created. It does not seem to have run the migration. I tried running the migration from the Heroku console, but I got:

~ $ rake db:migrate
rake aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (ActiveRecord::ConnectionNotEstablished)
        Is the server running locally and accepting connections on that socket?

I tried adding release: rails db:migrate to the procfile but that led to the same failure. When I first deployed the app, it did something similar, but eventually resolved itself, however, I don't want downtime every time I have a database change. I've deployed older versions of Rails to older versions of Heroku with no issues, so I believe there is something new in the deployment process


Solution

  • I explicitly added the DATABASE_URL to database.yml and now I can run rake db:migrate. The docs made it sound like this should have worked without setting it, but here's what I have in database.yml:

    production:
      primary: &primary_production
        url: <%= ENV["DATABASE_URL"] %>
        <<: *default