0

Apologies for the rookie question. I would like to make postgresql my default for all new rails apps. I'm aware of the command:

rails new my_app --database=postgresql

...but I have an irrational dislike for sqlite3 and for typing this extra command. I want my rails apps to love postgres monogamously, without me telling them they shouldn't hook up with sqlite3 first. How do I go about this?

I use rbenv (again, irrationally) to manage my ruby versions. Thanks in advance.

2 Answers 2

6

Create a .railsrc file in your HOME directory and put your db override there

# ~/.railsrc
--database=postgresql

You can add all other overrides that you might want to use, like --skip-test-unit or the like.

This file will be applied each time you run a rails new command.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you! Where is the origin of the sqlite3 dependency? And would I be able to change it there?
@apiary9 sqlite3 as a default database? Hardcoded in rails new, I think. You don't want to change it there. That's what these overrides are for.
Ah, an answer finally! Thank you, kind internet expert!
@apiary9: don't forget to accept helpful answers :)
Can I specify the database version in .railsrc? I would like to use sqlite v1.3.6
|
0

you can change default database by changing database.yml according to given file and don't forget to add pg gem in route gemfile like this gem 'pg'

development:
  adapter: postgresql
  encoding: utf8
  database: project_development
  pool: 5
  username: 
  password:

test: &TEST
  adapter: postgresql
  encoding: utf8
  database: project_test
  pool: 5
  username: 
  password:

production:
  adapter: postgresql
  encoding: utf8
  database: project_production
  pool: 5
  username: 
  password:

if this did'nt help you see the rails cast Migrating to PostgreSQL

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.