ActiveRecord::AdapterNotSpecified: 'postgresql' database is not configured - ruby-on-rails

I trying to figure out how fix the active record problem so I can push to heroku.
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
ActiveRecord::AdapterNotSpecified: 'postgresql' database is not configured. Available: ["development", "adapter", "encoding",
"database", "host", "pool", "username", "password", "production"]
development:
adapter: postgresql
encoding: unicode
database: sample_app_development
host: localhost
pool: 5
username: sample_app
password:
test:
adapter: postgresql
encoding: unicode
database: sample_app_test
host: localhost
pool: 5
username: sample_app
password:
production:
adapter: postgresql
encoding: unicode
database: sample_app_production
host: localhost
pool: 5
username: sample_app
password:

There is a space before development in the db config. I believe To fix it, simply remove space from the first line and follow the indentation.

I think you need to write this command on terminal to create you database:
rake db:create
Then run rake db:migrate to run your migrations

Remove spaces on 1st line " development:"
Make sure of the database name e.g. "sample_app_development" or just "sample_app"
gem install pg
rake db:create
rake db:migrate

First install postgresql
gem install pg
Then create project using following command:
rails new myapp -d postgresql

Related

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.
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

rake assets:precompile RAILS_ENV=production Error

I want to deploy a spree app to heroku and in order to do that I need to precompile my assets locally
I did
heroku addons:create heroku-postgresql
then I added config/application.rb
config.assets.initialize_on_precompile = false
my database.yaml file is
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
host: localhost
database: anzels_development
username: anzels
password: 1234
test:
<<: *default
host: localhost
database: anzels_test
username: anzels
password: 1234
production:
adapter: postgresql
encoding: unicode
database: anzels_production
pool: 5
password:
and whenever I run
sumeet#sumi-pc:~/anzels$ rake assets:precompile RAILS_ENV=production
I get an error
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: role "sumeet" does not exist
/home/sumeet/anzels/config/environment.rb:5:in `<top (required)>'
PG::ConnectionBad: FATAL: role "sumeet" does not exist
/home/sumeet/anzels/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)
config/enviormenr.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
please help
In local computer you are trying to run
rake assets:precompile RAILS_ENV=production
but this requires your local compute to have config/database.yml with the config mentioned by #thieu-nguyen
so add the following in
username: $PRODUCTION_DB_USER
password: $PRODUCTION_DB_PASS
under production in config/database.yml
then add the environment for you local computer as
PRODUCTION_DB_USER=anzels
PRODUCTION_DB_PASS=1234
and for heroku as
PRODUCTION_DB_USER=user
PRODUCTION_DB_PASS="" (empty)
ANOTHER EASIER WAY IS
username: anzels
password: 1234
to production in config/database.yml **JUST BEFORE assests precompilation **
then run command
git checkout config/database.yml
JUST BEFORE GIT COMMIT command
the idea is to not to commit the username and password but temporarily edit it for assests precompilation purpose only
Please add username and password to production config in database.yml or you need to create new role for postgres with name "sumeet".
production:
adapter: postgresql
encoding: unicode
database: anzels_production
pool: 5
username: anzels
password: 1234

bundle exec rake db:migrate hangs on Amazon EC2 and RDS

I have an EC2 instance (m3.medium) that runs my Rails application and connected to an RDS instance for the MySQL database.
When running 'bundle exec rake db:migrate', the process hangs indefinitely without outputting any error. Any ideas on how to debug this?
Edit the database.yml as:-
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: database_name
pool: 5
username: username
password: password
host: abcdef.amazonaws.com
Run the migration as:-
bundle exec rake RAILS_ENV=production db:migrate

Rails with Octopus gem. How to create db's defined in shards.yml with rake

I need to configure my app to use multiple shards, and even multiple db adapters. I have noticed that all rake commands like rake db:migrate are working, and have consequence on shards defined in shards.yml, except rake db:create.
It will be a real pain to create all this manually.
How can I make it work?
My database.yml (I have defined here, only my master shard)
development:
adapter: postgresql
host: localhost
encoding: unicode
database: db_workload_master_development
pool: 5
username:
password:
production:
......
My shards.yml
octopus:
environments:
- production
- development
development:
shards:
mysql:
host: localhost
adapter: mysql2
database: db_workload_mysql_shard_development
sqlite:
host: localhost
adapter: sqlite3
database: db_workload_sqlite_shard_development
pg:
host: localhost
adapter: postgresql
database: db_workload_pg_shard_development
pool: 5
username:
password:
production:
....
Only db's from database.yml are created with rake-task rake db:create.
I would recommend creating your own rake task that will read the shards.yml and create the db's as appropriate.
I think the Octopus gem using shards rake task like db
Try rake shards:create

How to configure Postgresql with rails project?

I am very new to ruby. I am trying to run BBYIDX and followed How to install BBYIDX on Windows?
When I try rake db:migrate it reproduces error as
(in /home/virinchy/BBYIDX-2/BBYIDX-master)
DEPRECATION WARNING: Rake tasks in vendor/plugins/acts_as_tsearch/tasks, vendor/plugins/acts_as_tsearch/tasks, vendor/plugins/delayed_job/tasks, vendor/plugins/nested_scenarios/tasks, vendor/plugins/rails-authorization-plugin/tasks, and vendor/plugins/rails_rcov/tasks are deprecated. Use lib/tasks instead. (called from /usr/local/rvm/gems/ruby-1.8.7-p371/gems/rails-2.3.11/lib/tasks/rails.rb:10)
rake aborted!
FATAL: password authentication failed for user "bbyidx"
FATAL: password authentication failed for user "bbyidx"
Bundle install was succesful with message as:Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
But rake db:migrate produces this error. I am running ubuntu 12.04, ruby-1.8.7, rails-2.3.11 and gem 1.5.3
How do i solve this?
Thanks in advance.
Did you set a password for your postgres user?
In your config/database.yml you should have your databases set up properly:
development:
adapter: postgresql
encoding: unicode
database: your_app_development # name your development app something
host: localhost
pool: 5
username: your_username
password: your_password # or leave blank if you didn't set a password
test:
adapter: postgresql
encoding: unicode
database: your_app_test
host: localhost
pool: 5
username: your_username
password: your_password

Resources