LoginSignup
0
0

More than 3 years have passed since last update.

bin/rails db:createできない

Last updated at Posted at 2020-11-01

起こった問題

$rails new project_name -d postgresql
の後、プロジェクトディレクトリに移動して、bin/rails db:createしたが、

以下エラーが出てきた

Could not find gem 'pg (>= 0.18, < 2.0)' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems

なのでbundle installをすると..

An error occurred while installing pg (1.2.3), and Bundler cannot
continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'`
succeeds before bundling.

Qiita記事: gem install pg が失敗するときの対処法とかも試したが、うまく行かなかった。

解決方法

結果的にはこのサイトで解決した。

brew install postgres
bundle install
③再度bin/rails db:create
で成功した。

感想

TOEICの勉強で1ヶ月ほどプログラミングに触れてなかったので、いきなりのエラー文にチキったけど、わりとすんなり解決できて安心しました☺️
1ヶ月もやってないと、「bin/rails db:createってなんだっけ」「あれターミナル上で編集するのってどうやるんだっけ(答え: vim)」、とか「あーーー現状位置確認するのってpwdだったな〜」って感じです。メチャクチャ基本的な事も忘れてしまっててびっくり。半年間の独学だと記憶の定着も薄いですね。

後日談

ちなみにこの後このQiita記事と同様の問題が出ました。
以下コマンドのみでとりあえず解決。

$ rails webpacker:install

そしてやっとrails sできたと思ってlocalhost:3000にアクセスできたと思ったら
Screen Shot 2020-11-01 at 17.29.24.png

なんでこんなにエラーばっか出るんだ?と思いつつ、
この記事に書いてあった

$ brew services start postgresql
$ brew services stop postgresql
$ brew services restart postgresql

を実行。そしたらまた違うエラーが😭なんで〜

ActiveRecord::NoDatabaseError (FATAL:  database "genba_rails_development" does not exist
):

Screen Shot 2020-11-01 at 17.33.06.png

とりあえずエラー文をググったらこのQiita記事が出てきたので、もう一度rails db:createしてみたら見慣れた画面に。よかった〜
Screen Shot 2020-11-01 at 17.35.44.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0