Rails: Postgres + rake db:structure:dump using wrong user - ruby-on-rails

I'm trying to dump the structure of my remote database using rake's rake db:structure:dump, but whenever I run that command it ignores the user in my database.yml file and uses the user on my local machine that I'm logged in as.
Database.yml:
development: &DEFAULT
adapter: postgresql
host: remoteaddress.com
port: 5432
user: myusername
password: mypassword
database: mydatabase
This is what happens when I run the command:
[~/src/myapp]$ RAILS_ENV=development rbbe rake db:structure:dump --trace ✭ git:em-redshift ruby:2.2.0
** Invoke db:structure:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:structure:dump
pg_dump: [archiver (db)] connection to database "mydatabase" failed: FATAL: password authentication failed for user "emai"
FATAL: password authentication failed for user "emai"
rake aborted!
Error dumping database
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:55:in `structure_dump'
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:182:in `structure_dump'
/opt/rubies/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:276:in `block (3 levels) in <top (required)>'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/opt/rubies/2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/opt/rubies/2.2.0/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/opt/boxen/rbenv/versions/2.2.0/bin/rake:33:in `<main>'
Tasks: TOP => db:structure:dump
As you can see, it doesn't use myusername as the user. Instead it runs it as my local user (emai). What is going on?
P.S. I know the db config works too, because I went into the rails console and queried for records and got results. Also, rake db:schema:dump works with no authentication errors.

After looking into the docs (https://github.com/rails/rails/blob/master/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb), you need to add a username key to get it to work... seriously...
development: &DEFAULT
adapter: postgresql
host: remoteaddress.com
port: 5432
user: myusername
username: myusername <-------
password: mypassword
database: mydatabase

Jsut replace user with username.

Related

Rails cannot connect to mysql server windows 10

I'm trying desperately to connect my new project / any project at all to the mysql2 server. I'm not really sure whether I've correctly installed MySQL server 5.7.21 or not but perhaps someone could advise.
I'm running ruby 2.3, rails 5.0.7 and mysql2 0.5.1. I definitely have mysql2 in my gemfile. I am running this on my 64-bit laptop with Windows 10
Every time I run a rails db:schema:dump from my project file in the command prompt, it shows this error:
C:\Users\MR_ra\Documents\Sites\matt_radin_cms>rails db:schema:dump --trace
** Invoke db:schema:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:schema:dump
rails aborted!
Mysql2::Error::ConnectionError: Can't connect to MySQL server on 'localhost'
(10061)
C:/Ruby23/lib/ruby/gems/2.3.0/gems/mysql2-0.5.1-x86-mingw32/lib/mysql2/client.rb:90:in `connect'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/mysql2-0.5.1-x86-mingw32/lib/mysql2/client.rb:90:in `initialize'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `new'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/mysql2_adapter.rb:25:in `mysql2_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:729:in `new_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:773:in `checkout_new_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:752:in `try_to_checkout_new_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:713:in `acquire_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:490:in `checkout'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:883:in `retrieve_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_handling.rb:128:in `retrieve_connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/connection_handling.rb:91:in `connection'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/railties/databases.rake:241:in `block (4 levels) in <top (required)>'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/railties/databases.rake:240:in `open'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/activerecord-5.0.7/lib/active_record/railties/databases.rake:240:in `block (3 levels) in <top (required)>'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `block in execute'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `each'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:271:in `execute'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:213:in `block in invoke_with_call_chain'
C:/Ruby23/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:193:in `invoke_with_call_chain'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/task.rb:182:in `invoke'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:160:in `invoke_task'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `each'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:116:in `block in top_level'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:125:in `run_with_threads'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:110:in `top_level'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:14:in `block in run_rake_task'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/rake-12.3.1/lib/rake/application.rb:186:in `standard_exception_handling'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-5.0.7/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:schema:dump
Currently my databases.yml file is looking like this:
default: &default
adapter: mysql2
host: localhost
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: ***********
password: ***********
My question is also to answer what does the localhost 10061 refer to?
If your databases.yml file only like this which is you shared your question then you update little bit like this
default: &default
adapter: mysql2
host: localhost
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: xxxxxxxxxxx
password: xxxxxxxxxxx
#=> if live server
#=> socket: /var/run/mysqld/mysqld.sock
#=> for developmen
development:
<<: *default
database: project_development
#=> for test
test:
<<: *default
database: project_test
#=> for production
production:
<<: *default
database: project_production
username: xxxxxxxxxx
password: xxxxxxxxxx
then rails db:create
Actually, that is my configuration which already working
Note: If you developing locally and not set any password for mysql then username and password will look like this
username: root
password:
If you use WAMP or XAMPP you must run this before running rails command. The WAMP is recommended for windows.
that means by default username is root and password is empty.
You can by default set up this configuration if you will run this command for creating a Rails project
rails new project_name -d mysql

ActiveRecord::No Database Error Fatal: Role "..."does not exist

I'm working a project collaboratively with others. It is deployed to heroku and it we're using postgresql.
I want to make changes in a local branch and see my changes in the web browser right away.
How can I do this with heroku?
I'm working in Cloud9 development environment and I used to enter "rails s -p $PORT -b $IP" to view my changes in the app, but now when I do that, I get a "no database error."
I've tried googling things but I'm still confused. How can I make changes to an exisiting app and see my changes locally (without pushing to origin/master)? I've never worked with databases before... using the pre-programmed cloud9, things were just working. I'm not sure how to create a separate database for heroku if that's what is needed.
Here is a copy of 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: sqlite3
# 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:
# <<: *default
# database: db/production.sqlite3
# FOR HEROKU -- POSTGRES DB SETUP
# UNCOMMENT WHEN WORKING LOCALLY.
development:
adapter: postgresql
database: planit_developement
pool: 5
timeout: 5000
test:
adapter: postgresql
database: planit_test
pool: 5
timeout: 5000
# production:
# <<: *default
# database: db/production.sqlite3
Here is the full trace when I try to migrate:
rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: role "ubuntu" does not exist
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:665:in `rescue in connect'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `connect'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:87:in `connection'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:913:in `initialize'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `new'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:820:in `up'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/migration.rb:798:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
Tasks: TOP => db:migrate

Rails rake aborted! can't convert Hash into String

Ok i had this working and i'm not sure what i could have changed to make rake db:create not working now. I ran rake db:drop to drop my db so i can start from scratch and now rake db:create is having a problem.
Here's my stacktrace below. I'm not sure how to go about troubleshooting this.
$ rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
rake aborted!
can't convert Hash into String
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/mysql2_adapter.rb:17:in `new'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/mysql2_adapter.rb:17:in `mysql2_connection'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:304:in `new_connection'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:323:in `checkout_new_connection'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block (2 levels) in checkout'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `loop'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `block in checkout'
/Users/TomCaflisch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:260:in `checkout'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:162:in `connection'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `retrieve_connection'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/railties/databases.rake:86:in `rescue in create_database'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/railties/databases.rake:54:in `create_database'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/activerecord-3.1.8/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/task.rb:227:in `call'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/task.rb:227:in `block in execute'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/task.rb:222:in `each'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/task.rb:222:in `execute'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/TomCaflisch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/task.rb:152:in `invoke'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:141:in `invoke_task'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:99:in `block (2 levels) in top_level'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:99:in `each'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:99:in `block in top_level'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:108:in `run_with_threads'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:93:in `top_level'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:71:in `block in run'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exception_handling'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/lib/rake/application.rb:68:in `run'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/gems/rake-10.0.2/bin/rake:37:in `<top (required)>'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/bin/rake:19:in `load'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/bin/rake:19:in `<main>'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/bin/ruby_noexec_wrapper:14:in `eval'
/Users/TomCaflisch/.rvm/gems/ruby-1.9.3-p327#famnfo/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:create
database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: mysql2
encoding: utf8
database: FamNFo_development
# local
username: root
password:
# server
# username: famnfo_dev
# password: Panther89!1
# local
socket: /tmp/mysql.sock
# server
# socket: /var/lib/mysql/mysql.sock
# 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: mysql2
encoding: utf8
database: FamNFo_test
# local
# username: root
# password:
# server
username: root
password:
# local
socket: /tmp/mysql.sock
# server
#socket: /var/lib/mysql/mysql.sock
production:
adapter: mysql2
encoding: utf8
database: FamNFo_production
# local
# username: root
# password:
# server
username: myusername
password: mypassword
# local
# socket: /tmp/mysql.sock
# server
socket: /var/lib/mysql/mysql.sock
When you have extra leading spaces before a key in your YAML file it is interpreted as a sub-key, and thus the upper key is interpreted as a hash instead of a string. So removing the extra space before socket in the test section should fix the problem.

rake aborted! syntax error on line 1, col 9: ` adapter: sqlite3'

I'm trying to use mysql as a database in production enviroment as sugested on page 234, chapter 16 of my Agile 4rth edition. As far as I know that this question looks like the one that danymmc asked on january (http://stackoverflow.com/questions/8809099/rails-app-rake-dbmigrate-aborted-syntax-error) the solution doesn't fit to me.
I'm working with:
Ruby 1.9.2
Rails 3.1.0
rubygems 1.8.18
My database.yml is:
development:
adapter: sqlite3
database: development
pool: 5
timeout: 5000
production:
adapter: mysql
database: depot_production
encoding: utf8
host: localhost
password: password
pool: 5
reconnect: false
socket: /var/run/mysqld/mysqld.sock
username: username
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
When I trace the rake db:setup RAILS_ENV="production" I get:
root#HAL3:/var/www/repos/depot/depot_old# rake db:setup RAILS_ENV="production" --trace
** Invoke db:setup (first_time)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
syntax error on line 1, col 9: ` adapter: sqlite3'
/usr/local/rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/syck.rb:135:in `load'
/usr/local/rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/syck.rb:135:in `load'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.0/lib/rails/application/configuration.rb:100:in `database_configuration'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/local/rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `<main>'
Tasks: TOP => db:setup => db:create => db:load_config
I tried to include this code to the config/boot.rb file and it doens't worked:
require 'yaml'
YAML::ENGINE.yamler = 'syck'
I tried to update my gems with
gem update -system
and it doesn't work too.
The most interesting thing is that my development machine and the production one are the same and, of course, in development (localhost:3000 with rails server up) works perfectly.
Any help will be appreciated.
Try with this database.yml:
development:
adapter: sqlite3
database: development
pool: 5
timeout: 5000
production:
adapter: mysql
database: depot_production
encoding: utf8
host: localhost
password: password
pool: 5
reconnect: false
socket: /var/run/mysqld/mysqld.sock
username: username
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
Mind the spaces, that are significant
The issue could be that you have your test environment nested 1 space too deep causing invalid YML. Make sure it is indented 2 spaces rather than 3.
You can use hostname: instead of host in database.yml file.

rake db:create "unknown could'n parse YAML" sqlite3

Hi I am trying to add a db to my rails app. I have created a db using sqlite3 called proto_development but when I go to use the rake db:create command I get the following error
ROOT\first_app>rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
(<unknown>): couldn't parse YAML at line 9 column 12
C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse'
C:/Ruby193/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
C:/Ruby193/lib/ruby/1.9.1/psych.rb:125:in `parse'
C:/Ruby193/lib/ruby/1.9.1/psych.rb:112:in `load'
ROOT/first_app/sqlite3-ruby/ruby/1.9.1/gems/railties-3.1.0/lib/rails/application/configuration.rb:
100:in `database_configuration'
ROOT/first_app/sqlite3-ruby/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/railties/database
s.rake:6:in `block (2 levels) in <top (required)>'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `call'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `each'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:176:in `block in invoke_prerequisites'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:174:in `each'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:174:in `invoke_prerequisites'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:157:in `block in invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
C:/Ruby193/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `each'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
C:/Ruby193/lib/ruby/1.9.1/rake/application.rb:63:in `run'
C:/Ruby193/bin/rake:32:in `<main>'
Tasks: TOP => db:create => db:load_config
Below is my YAML file:
# SQLite version 3.x
# gem install sqlite3
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/proto_development.sqlite3
pool: 5
timeout: 5000
username: root
password: "p"
# 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: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
username: root
password: "p"
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
username: root
password: "p"
Any help you could offer would be much appreciated.
Thanks
Make sure your password in your database.yml file is a string, as in not all numbers. For example, 321 would pull an error, b321 would work. This may work.

Resources