Fresh Rails App Defaulting to Postgres Instead of SQLite3

Fresh rails app defaulting to Postgres instead of SQLite3

The problem is that when you start the server it is looking for environment variable DATABASE_URL which is probably set to postgres and this takes precedence over the database.yml file. You can delete the environment variable, and it should work, or you can reset it to SQLite.

How do I change rails' default database from sqlite3 to postgres, across all new projects?

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.

Change from SQLite to PostgreSQL in a fresh Rails project

You can change your database.yml to this instead of using the out of the box sqlite one:

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:

cucumber:
<<: *TEST

How to switch my Rails app to postgresql from Sqlite3?

You'll want to edit config/database.yml to use postgresql instead of sqlite.

The migrations in db/migrate/*.rb are hopefully cross-database compatible, and wont need to be changed.

Running rake db:create db:migrate with the new database.yml should create the PostgreSQL database and you'll be up and running.

In reality, you'll probably run into various problems, but this will be a starting point.



Related Topics



Leave a reply



Submit