[RUBY] [heroku] run rails db: migrate doesn't work


・ Rails ・ Mysql Ver 14.14 Distrib 5.6.47 ・ Osx10.15 ・ Deploy to heroku


This is a response when something goes wrong when creating an app with Rails and uploading it to heroku. In the development environment, MySQL and heroku have DB as PostgreSQL, so it is necessary to support it. An error occurred in the middle of the process. I will write in order.

Support for PostgreSQL

First, write the following in Gemfile. It uses PostgreSQL in a production environment. I wrote at the bottom.

group :production do
  gem 'pg'

I changed the Gemfile, so don't forget to do bundle install. First of all, it was the first error here. If you do bundle install as it is, an error occurs because there is no PostgreSQL in your development environment.

Correspondence is to execute the command to skip the place of group: produciton end in the terminal.

$ bundle install --without production 

Put the description to connect to the database to database.yml in the config folder. I added it to the bottom.

  <<: *default
  adapter: postgresql
  encoding: unicode
  pool: 5

That's all for me. The article that was helpful is here! [For beginners] How to reliably deploy rails apps using heroku [Definitive edition] ・ Htps: // Quiita. This m / Kazuki Tsumoto / Te ms / A 0 Da 7281 A 3948701c39

Deploy to heroku

I will omit it here this time. Proceed to the completion of deployment.

Here db: migrate

I do heroku run rails db: migrate but an error occurs! I finally come across this error while looking at various things. .. ..

The following description is in the middle of the terminal.

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?


The simple thing is that heroku doesn't include PostgreSQL by default, so you'll need to add it! What! !! !! !! I'm not used to it yet so I didn't notice this simple thing. .. .. ..


Command to add PostgreSQL in the terminal

$ heroku addons:create heroku-postgresql

After that

$ heroku run rails db:migrate

Then the migration is complete!

I thought something else was wrong and spent hours doing something completely different, but it was simple! The app works and is complete!


[For beginners] How to reliably deploy rails apps using heroku [Definitive edition] ・ Htps: // Quiita. This m / Kazuki Tsumoto / Te ms / A 0 Da 7281 A 3948701c39

[Rails] About the error that occurs when trying to execute "heroku run rake db: migrate" ・ Https://qiita.com/suzuki-x/items/b878723080aea1a673ed

Recommended Posts

[heroku] run rails db: migrate doesn't work
PG :: DatatypeMismatch error when doing heroku run rails db: migrate
rails db: migrate failed!
[Beginner] When rails s doesn't work
[Rails] Modify migrate file (rails db: rollback)
SCSS doesn't work when deploying Rails6 AWS
rails generate doesn't work at all! Sometimes try
After all, what is [rails db: migrate] doing?
[Rails MySQL] How to reset DB on heroku
rails db: 〇〇 Summary
[Rails] "private method` String' called ~ "error when db: migrate
[Ruby On Rails] How to reset DB in Heroku
Test run on rails
Heroku app moving (rails)
[Rails] rails db command summary
rails heroku error log
[Rails] Heroku deployment flow
Rails server doesn't start.
When I run rails: db: migrate, I get "Directly inheriting from ActiveRecord :: Migration is not supported."
# What to do if you accidentally do rails db: migrate: drop