ビーコンの創出

なんか作ったり報告したり。

RailsでPostgreSQLが動作しない 解決方法

バージョン

Rails 5.1.4
ruby 2.4.0


SQLite3だとできていたのにPostgreSQLでdb:migrateしたらエラーが発生。

rails aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
解決方法
initdb /usr/local/var/postgres
postgres -D /usr/local/var/postgres

postgresを起動させていないだけだった。

しかし

Caused by:
PG::ConnectionBad: FATAL: database "myapp_development" does not exist

となった。データベースを作成する必要がある。

rake db:create
rake db:migrate

うまく動作した。

sqlite3だとこんなことしなくてよかったので気づかなかった。