chell
chell

Reputation: 7866

Can't create production database for Rails app

I'm trying to create the database for my Rails app in production mode using Postgresql.

When I run the command:

$ RAILS_ENV=production rake db:create

I get the following error:

FATAL:  database "postgres" does not exist
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "database"=>"provenword", "pool"=>5, "username"=>"postgres", "password"=>"password"}

I can create a database for older Rails apps that I have. However, only this one gives me this error. How can I get this to work so I can create the database and run the application?

Gem file:

..
    gem 'pg'
..

Rails Version - 4.2.6

database YML

#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

# default: &default
# user: postgres
# password: password
# pool: 5
# timeout: 5000



development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: provenword
  pool: 5
  username: postgres
  password: password

Postgresql is installed on my server.

Upvotes: 0

Views: 1416

Answers (1)

ChaosPredictor
ChaosPredictor

Reputation: 4091

Thanks to @Dharam.

It's work for me as well:

I beleive postgresql expects a database with the same name as the user name, in your case postgres, be present. First setup a database with the name postgres then you can run RAILS_ENV=production rake db:create

Upvotes: 1

Related Questions