I cant seem to find an up-to-date guide to creating a new Rails 3.1 app with a Postgresql database. I would greatly appreciate a guide through that process.
Since Rails 3, the framework is completely database-agnostic.
What that means is, all you have to do is 2 things:
pg
gem in your Gemfile: gem 'pg'
database.yml
file is using postgresql
as the adapter.You can accomplish this automatically when you create a new app by appending the --database=postgresql
flag:
rails new myapp --database=postgresql
But if you've already created the app, then just comment out gem 'sqlite3'
in your Gemfile, add in gem 'pg'
, run bundle
, and then change your database.yml
file to use the correct adapter.
Of course, it goes without saying that you will also need to install PostgreSQL itself, but that is something you can easily find on google.
To elaborate on bricker's answer... After running:
$ rails new myapp --database=postgresql
Here is what your database.yml will look like:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: myapp
password:
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
username: myapp
password:
production:
adapter: postgresql
encoding: unicode
database: myapp_production
pool: 5
username: myapp
password:
Running:
$ bundle exec rake db:create:all
will create the databases for you if you have PostgreSQL installed. The easiest way to install PostgreSQL is http://postgresapp.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With