rake aborted! can't convert nil into Hash - ruby-on-rails

rake aborted! Cannot load Rails.application.database_configuration: can't convert nil into Hash
I am trying to deploy ruby on rails on openshift, and then i try to run rake db:migrate. Then i face this problem.
I create the app with https://github.com/kohjx/TestYourCode.git on openshift with ruby on rails + mysql 5.1
Then i configure the config/database.yml
default: &default
#adapter: sqlite3
adapter: mysql2
pool: 5
timeout: 5000
database: "<%=ENV['OPENSHIFT_APP_NAME']%>"
username: "<%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%>"
password: "<%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%>"
host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%>
development:
<<: *default
#database: db/development.sqlite3
test:
<<: *default
#database: db/test.sqlite3
database: testyourcode_test
production:
<<: *default
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
#database: db/production.sqlite3
I setup the RAILS_ENV=development, but i can't figure out how to solve. Any help would be greatly appreciated!

At first glance it looks like you're using the Openshift DB as your default and then all your Rails environments are using that default setup. Your local machine (where I'm assuming you're running the rake db:migrate) isn't able to use those connection details to the OPenshift DB.
Instead of having the Openshift DB configuration in the default section move it down to the production setting and switch the RAILS_ENV=production with rhc set-env RAILS_ENV=production. Then configure the development with settings that your localmachine can use. After thats all done, try running your db:migrate once more.

Related

We're sorry, but something went wrong. - Heroku Hosting

I wanted to try Heroku as a hosting method. I can go to the home page, but when I press "Sign Up" I get "We're sorry, but something went wrong." message.
Is there any way of using sqlite3 instead of Postgres? If not on Heroku, then maybe on some different hosting service?
I watched the logs but cannot see the issue there.
default: &default
database: db/development.sqlite3
adapter: postgresql
pool: 5
timeout: 5000
development:
adapter: postgresql
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:
adapter: postgresql
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: postgresql
database: db/production.sqlite3
pool: 5
timeout: 5000
I just get the "We're sorry, but something went wrong." error message
Please go to https://crassar.herokuapp.com and watch it your self
Install Heroku Postgres add-on. It's free for Hobby Dev.
Get postgres (database) url from Heroku Postgres
Add url to config vars on Heroku, like this: (Settings -> Reveal Config Vars)
variable name: DATABASE_URL
value: postgres://blabla
Edit database.yml for production
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>

ActiveRecord::ConnectionNotEstablished for new project

I made a wrong choice and now I am sticked at the middle of my project
I used ruby 5.0.0rc1, and while I start my project with rubymine I get "ActiveRecord::ConnectionNotEstablished"
I also get an error message while I type rake db:create :
Gregoires-MacBook-Pro:p1 gregoire$ rake db:create
Rake tasks not supported by 'pg' adapter
Couldn't create database for {"adapter"=>"pg", "pool"=>5, "timeout"=>5000, "database"=>"pg"}
rake aborted!
ActiveRecord::Tasks::DatabaseNotSupported: Rake tasks not supported by 'pg' adapter
my database/yml :
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: 'pg'
pool: 5
timeout: 5000
development:
<<: *default
database: 'pg'
test:
<<: *default
database: 'pg'
production:
<<: *default
database: 'pg'
I am newbie with ror , any help will be appreciated (please detail)
greg
config/database.yml gives Rails the information needed to access the database of your choice.
The adapter name pg is not valid. If you intend to use PostgreSQL, you should set it as postgresql.
And you have to make sure PostgreSQL is installed and running.
A typical database.yml could be like the following:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
timeout: 5000
username: your_username_for_postgresql
password: your_password_for_postgresql
development:
<<: *default
database: your_app_name_development
test:
<<: *default
database: your_app_name_test
production:
<<: *default
database: your_app_name_production
username: your_username_for_postgresql_on_production
password: your_password_for_postgresql_on_production
Thanks for your answers, I had multiple problems :
1/ Postgresql was not properly installed AND running
Fresh install using some comments found here :
https://gist.github.com/lxneng/741932
2/ my database .yml was nos properly configured, I created users with
new access : http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/
What you gave me as advise made me find the way, also a project 'out of the box' was not runable
Thanks for your time and advises
greg

Rake tasks seem to ignore database.yml configuration

I am using MAC OS X along with postgresql installed via Homebrew. I am developing using Rails 4.2.1 and ruby 2.2.0. The connection with postgresql server is fine but for some reason every application accesses the database "kstavrou" which is my system username, as a development database and creates the rest as defined by database.yml. That is troublesome if you have more than 1 rails app.
rake db:create output:
Konstantinoss-MacBook-Pro:ecomm-intel kstavrou$ rake db:create
kstavrou already exists
ecomm_intel_test already exists
strange thing is that if I empty database.yml still connects fine to postgresql and tries to create again the database "kstavrou" executing there all the migrations, without trying to create the test database.
rake db:create output:
Konstantinoss-MacBook-Pro:ecomm-intel kstavrou$ rake db:create
kstavrou already exists
database.yml
default: &default
adapter: postgresql
host: localhost
encoding: utf8
username: pguser
password: 123456
pool: 5
production:
<<: *default
database: ecomm_intel_prod
development:
<<: *default
database: ecomm_intel_dev
test:
<<: *default
database: ecomm_intel_test
Well the problem was that the ENV['DATABASE_URL'] was set (by some install script) so it was overwriting the database.yml configuration, as noted by steve klein, so I just removed it.
`export DATABASE_URL=postgres:///$(whoami)`

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

Database connection on Heroku

Wow I've been stuck on this one for days. I'm having trouble connecting to database.yml on Heroku. I'm on Cedar and ruby 1.9.2. My dev and test dbs are sqlite3 and the prod db is postgreSQL to cope with Cedar rules.
Here is the code in my ruby script:
Rails.env.production? ? (env = "production") : (env = "development")
dbconfig = YAML::load(File.open('config/database.yml'))[env]
ActiveRecord::Base.establish_connection(dbconfig)
All goes well in local but when I push to Heroku, I get:
ArgumentError: syntax error on line 17, col 0: `adapter = uri.scheme'
from /usr/local/lib/ruby/1.9.1/syck.rb:135:in `load'
It looks like Heroku doesn't like my database.yml. Here's an overview:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: unicode
database: foo
port: 5432
host: foobar.amazonaws.com
username: foo
password: bar
First, Heroku overwrites your config/database.yml with its own Heroku-specific version. That's how Heroku automatically connects your application to its own postgresql databases. To tell Heroku about your own posgresql database, you should set up the correct config variables and you might as well omit the production database from your the config/database.yml in your repository because Heroku will ignore it anyway.
Second, the config/database.yml file is an ERB template for a YAML file. You must first run the file contents through Evaluated Ruby (ERB) before running the the output through YAML.

Resources