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.
4 Answers
Since Rails 3, the framework is completely database-agnostic.
What that means is, all you have to do is 2 things:
- Include the
pggem in your Gemfile:gem 'pg' - Make sure your
database.ymlfile is usingpostgresqlas 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.
6 Comments
rails new command posted in the answer and take a look at the generated database.yml file. (It shows: adapter: postgresql)database.yml file it should be in your_app/config/database.ymlTo 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/
bundleand you're finished.