简体   繁体   中英

How can I get rails to use pg by default?

It's not a huge burden but I would really like to be able to change the default gem-set on my rails apps when I create them so that they're ready for Heroku.

What is the best way to go about doing this?

You can specify the database with -d when running rails new :

Usage:
  rails new APP_PATH [options]

Options:
  -d, [--database=DATABASE]   # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                              # Default: sqlite3

Description:
    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

So for PostgreSQL this is:

rails new myapp -d postgresql

To make this the default put -d postgresql into ~/.railsrc

Another option is to change gem 'sqlite3' to gem 'pg' in your Gemfile as suggested in Getting Started with Rails 3.x on Heroku .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM