LoginSignup
0
1

More than 5 years have passed since last update.

railsのDBをPostgreSQLに変更する

Posted at

前置き

タイトルママ
ralisのDBはデフォルトだとsqliteが使われてるので変更が少し面倒でした。

方法

①posgresqlをインストールする

$ brew install posgresql
$ pg_ctl -D /usr/local/var/postgres start #起動する
$ psql -l #DBのリストが表示されたら成功です

②railsの設定

$ rails new pg_app -D posgresql # rails newのオプションでDBをあらかじめ選択しておく
$ bundle install 

③DB初期化

rake db:create
rake db:migrate # これで完了!

補足

Macだと①のpsql -lでリストがうまく表示できないことがある。
これはMacにデフォルトでインストールされているposgresqlが邪魔になっているのが理由らしい。
その場合は、修正batchを用いて

$ cd /usr/local/Cellar/postgresql
$ curl -o fixBrewLionPostgresql.sh http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh
$ chmod 777 fixBrewLionPostgresql.sh
$ ./fixBrewLionPostgresql.sh

これを流した後に、

$ pg_ctl -D /usr/local/var/postgres restart #再起動してあげる

で、繋がる(はず)

参考

http://taise.hatenablog.com/entry/2013/10/13/162546
http://kgmx.hatenablog.com/entry/2014/04/08/085425

0
1
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
1