I am trying to deploy my app on heroku . For that I changed from sqlite3 to pg because heroku doesn't support sqlite3. I changed things in database.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.pg
# 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.pg
production:
<<: *default
database: db/my_database_production.pg
I also did add the gem and install it (gem install pg) . When I try to run bundler exec rake db:create it gives me the following error:
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: role "flo" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:87:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:909:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `up'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:785:in `migrate'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I am trying to write su - postgres in my terminal but from that command I get :
No passwd entry for user 'postgres'
What should I do ?
You need to add the user 'flo' to your local postgres instance (I usually just add them as a super user so I don't have permissions issues). Run this in your terminal:
createuser -P -s -e flo
You will be prompted to set a password as well. Lets use 'flo' for now. You will then need to add this to your databases.yml file:
development:
<<: *default
database: db/development.pg
username: flo
password: flo
Do that and then try running rake db:create again. Check this out for additional help.
Related
I have an old app dating all the way back to Rails 2. We are currently upgrading it.
The database is refusing to create with the settings below. What could be going on?
When I run rake db:create:
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Running cron.rake
Running roles.rake
begin Rakefile
development
stack level too deep
Couldn't create 'project_dev' database. Please check your configuration.
rake aborted!
SystemStackError: stack level too deep
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/instance_variables.rb:15:in `block in instance_values'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/instance_variables.rb:15:in `map'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/instance_variables.rb:15:in `instance_values'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:63:in `as_json'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:180:in `block in as_json'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:179:in `each'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:179:in `as_json'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:63:in `as_json'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:180:in `block in as_json'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:179:in `each'
/Users/ss/.rvm/gems/ruby-3.1.0/gems/activesupport-7.0.2.2/lib/active_support/core_ext/object/json.rb:179:in `as_json'
... repeats many times ...
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= Rails.application.credentials.database[:username] %>
password: <%= Rails.application.credentials.database[:password] %>
development:
<<: *default
database: project_dev
host: localhost
test:
<<: *default
database: project_test
psql postgres:
postgres=# \du
Role name | Attributes | Member of
--------------+------------------------------------------------------------+-----------
applyco | Superuser | {}
postgres=# \list
(List does not include project_dev or project_test).
Remove the gem 'meta_request' to fix the issue.
Source: https://github.com/rails/rails/issues/40781#issuecomment-742807721
I cannot figure out why I am constantly getting this error when running rake db:migrate:status after switching over to Postgresql and Rails 5.2.1
[root:7e2d33988106:~/myapp]# rake db:migrate:status 12:04AM/06.27
rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/schema_migration.rb:22:in `table_exists?'
/usr/local/rvm/gems/ruby-2.5.1/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:124:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => db:migrate:status
(See full trace by running task with --trace)
What I've done so far
I have edited the pg_hba.conf file to show the following:
local all postgres md5
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
and restarted the service. No luck. Same error. The first error I got prior to this was invalid password for postgresql, so i had to change one of the "peer" options to "md5"
If I look into my config/database.yml file, this is what it looks like:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
encoding: unicode
username: postgres
database: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_name) %>
# username: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_user_name) %>
# password: <%= Rails.application.credentials.dig(:database, Rails.env.to_sym, :database_password) %>
development:
<<: *default
test:
<<: *default
staging:
<<: *default
production:
<<: *default
and when I edit the credentials with rake (using EDITOR=vim rails credentials:edit), this is what this file looks like:
# aws:
# access_key_id: 123
# secret_access_key: 345
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: <my long key redacted for stackoverflow>
database:
development:
database_name: development
database_user_name: postgres
database_password: <redacted for stackoverflow>
test:
database_name: test
database_user_name: postgres
database_password: <redacted for stackoverflow>
production:
database_name: production
database_user_name: postgres
database_password: <redacted for stackoverflow>
I feel like I've been going hours deep down the rabbit hole and cannot figure out how to get this Rails application working with Postgresql.
I have taken a look at this post here: PG::ConnectionBad fe_sendauth: no password supplied and have tried its suggestion with no luck, and even here How to resolve the error 'fe_sendauth: no password supplied' in Rails using PostgreSQL? with no luck either. I don't have host: '' or host: 'localhost' anywhere in the config/database.yml file (I've tried adding it and still didn't work), so I'm not quite sure this has anything to do with anything here for me.
Any other suggestions?
Add your username and password in production: in database.yml
So for background, I just got a new computer and put Xubuntu 13.04 on it, then proceeded to put on RVM, Ruby, and Rails. I've slowly been adding libs as I run into problems, but can't find the solution to this one.
When running rake db:migrate, I get the following output:
rake db:migraterake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:53:in `connection'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:863:in `initialize'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:764:in `new'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:764:in `up'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/migration.rb:742:in `migrate'
/home/erik/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/home/erik/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `eval'
/home/erik/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I think I've made the common edits to the pg_hba.conf:
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
and database.yml:
development:
adapter: postgresql
encoding: unicode
database: stevenagy
host: localhost
pool: 5
timeout: 5000
username: localhost
password:
test:
adapter: postgresql
encoding: unicode
database: stevenagy
host: localhost
pool: 5
timeout: 5000
username: localhost
password:
production:
development:
adapter: postgresql
encoding: unicode
database: stevenagy
host: localhost
pool: 5
timeout: 5000
username: localhost
password:
Any advice? Thanks!
There's no password directive in your database.yml entries, but your pg_hba.conf requires md5 password authentication. Specify a password for your connections, use an authentication method in pg_hba.conf that doesn't require a password, or put the passwords in the ~/.pgpass file if you don't want them in revision control.
I am attempting to use this bit of useful code from this question:
namespace :db do
namespace :test do
task :reset do
ActiveRecord::Base.establish_connection('test')
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
ActiveRecord::Base.establish_connection(ENV['RAILS_ENV']) #Make sure you don't have side-effects!
end
end
end
Unfortunately I am getting this error:
** Invoke db:test:reset (first_time)
** Execute db:test:reset
rake aborted!
database configuration does not specify adapter
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord- 3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
/home/nick/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
/home/nick/Projects/yumbin/lib/tasks/test_environment.rake:4:in `block (3 levels) in <top (required)>'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/nick/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/nick/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
./bundler_stubs/rake:16:in `load'
./bundler_stubs/rake:16:in `<main>'
Tasks: TOP => db:test:reset
As you can see I am using Ruby 1.9.3 via RVM. I am using Rails 3.2.5, Rake version 0.9.2.2 and Postgresql 9.1, and the pg gem (0.13.2). Additionally, I have no database errors in my environments. Thhe app is deployed and running on Heroku, runs locally in development, and I can run my full test suite without issue. In a Rails console running the line:
ActiveRecord::Base.establish_connection('test')
succeeds. I checked the database.yml in vi for invisible characters but could not find any. Only '$' at the end of each line. I'm starting to think that the answer is incredibly simple and in front of my nose but I just can't see it.
UPDATE: Adding my database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: unicode
database: myapp-dev
pool: 5
username: ******
password: *******
# 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
encoding: unicode
database: myapp-test
pool: 5
username: *****
password: ******
production:
adapter: postgresql
encoding: unicode
database: myapp
pool: 5
username: ******
password: *******
You need a test entry in your database.yml file, and I think you're probably lacking one. Make sure you have an entry that looks like this in database.yml:
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
Using whatever adapter and database your development database is using.
I am new to Stack Overflow and Ruby on Rails. My problem is, when I run the command rake db:create or rake db:migrate, the test database is affected, but the development database is not.
rails (3.2.2)
my database.yml:
# 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: &test
adapter: postgresql
encoding: unicode
database: ticketee_test
pool: 5
username: ticketee
password: my_password_here
development:
adapter: postgresql
encoding: unicode
database: ticketee_development
pool: 5
username: ticketee
password: my_password_here
production:
adapter: postgresql
encoding: unicode
database: ticketee_production
pool: 5
username: ticketee
password: my_password_here
cucumber:
<<: *test
Thanks for the suggestion, but I am afraid that isn't the reason. My RAILS_ENV=development. When I start the rails server, the server runs the development database. if I run "rails server -e test" then the server uses the test database. I am still not sure why migrations are running on my test database...
UPDATE:
Based on a suggestion, I commented out all of the database configurations except development, and now I get an error. I am running postgresql, I have the gem 'pg' installed. First, my new database.yml:
development:
adapter: postgresql
encoding: unicode
database: ticketee_development
pool: 5
username: ticketee
password: my_password_here
# 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: &test
# adapter: postgresql
# encoding: unicode
# database: ticketee_test
# pool: 5
# username: ticketee
# password: my_password_here
#production:
# adapter: postgresql
# encoding: unicode
# database: ticketee_production
# pool: 5
# username: ticketee
# password: my_password_here
#cucumber:
# <<: *test
My error message!
Someguys-MacBook-Air:ticketee someguy$ rake db:migrate
rake aborted!
database configuration does not specify adapter
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
Someguys-MacBook-Air:ticketee someguy$ rake db:migrate -t
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
database configuration does not specify adapter
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activerecord-3.2.2/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activerecord-3.2.2/lib/active_record/base.rb:718:in `<top (required)>'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/activerecord-3.2.2/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/someguy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/someguy/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/bin/rake:19:in `load'
/Users/someguy/.rvm/gems/ruby-1.9.3-p125#defaultGems/bin/rake:19:in `<main>'
Using the database.yml above, rake db:create:all RAN CORRECTLY and created my table. However, my migration still fails with the same stack trace as the one above.
I changed my database.yml to this:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
UPDATE: I completely changed my database.yml to this:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
cucumber:
<<: *test
Now, this is what happens when I run rake db:drop:all, followed by rake db:migrate. The rake db:migrate command runs a migration, creating a db/test.sqlite3 AND adding a table to it. So, my migration is still running on the test environment. When I run rake environment RAILS_ENV=development db:migrate, the same thing happens and I get a test.sqlite3 file...
There is a 'brilliant' line in
activerecord/lib/active_record/tasks/database_tasks.rb:
environments << 'test' if environment == 'development' && ENV['RAILS_ENV'].nil?
which, until jan 8, 2014 looked like:
environments << 'test' if environment == 'development'
I had the exact same problem starting last night. No idea what might have caused this, but finally found a solution that worked. Inside the configure block in config/environments/develop.rb, I added:
Rails.env = 'development'
I hope that works for you too
It sounds like your solution could be involving a couple of things. It's possible your your environment is confusing the migration because of existing elements. Reset your database using:
rake db:reset
or
rake db:drop db:create
depending on your environment, you should be able to do the migration.
rake db:migrate
PS - You may have to add bundle exec in the beginning of each command.
Good luck.
You are missing the host: localhost in your yml file.
Change your configuration to this:
development:
adapter: postgresql
encoding: unicode
host: localhost
database: ticketee_development
pool: 5
username: ticketee
password: my_password_here
Forking error!
Maybe some caching or log problems It shows that nothing of the errors in our code.
My team resolve it.
delete the project
git clone the project
config the database.yml
start server
Everything is okay!
The same project the errors gone!
So we think it is env problems or cach or log.
You can use rake db:migrate RAILS_ENV="development"
or you can use like
set RAILS_ENV=development
rake db:migrate