В моем файле database.yml задана нестандартная база данных: нет явного имени пользователя :. Если я использую rails c
и попытаться получить доступ все, что он терпит неудачу с, например:Почему консоль rails игнорирует мою конфигурацию config/database.yml: настройки?
2.2.2 :001 > User.connection
ActiveRecord::NoDatabaseError: FATAL: role "scope" does not exist
Если я пытаюсь явно подключиться, используя мои: параметры развития я вижу:
2.2.2 :005 > ActiveRecord::Base.establish_connection :development
=>
#<ActiveRecord::ConnectionAdapters::ConnectionPool:...
@config={:adapter=>"postgresql", :encoding=>"unicode", :database=>"scope", :pool=>5, :timeout=>5000, :port=>5432, :username=>"scope", :password=>"...", :host=>"127.0.0.1"},
...
Так это явно игнорируя мою пользовательскую базу данных и мое собственное имя пользователя. Как ни странно, если я переименую блок yaml с development:
на что-нибудь еще, например. staging:
, я могу установить соединение с ActiveRecord::Base.establish_connection :staging
и получить доступ к моим моделям.
Кто-нибудь знает, что может быть? У меня нет набора переменных окружения DATABASE_URL
, поэтому это не может быть переопределяющим. Что еще может вызвать такое поведение?
Вот фактический YML:
development:
adapter: postgresql
encoding: unicode
database: mydb_development
pool: 5
timeout: 5000
port: <%= ENV["BOXEN_POSTGRESQL_PORT"] || 5432 %>
И StackTrace:
2.2.2 :002 > User.count
ActiveRecord::NoDatabaseError: FATAL: role "scope" does not exist
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:665:in `rescue in connect'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `connect'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
from /Users/me/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
from /Users/me/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
... 11 levels...
from /Users/me/.rvm/gems/ruby-2.2.2/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:274:in `require'
from /Users/me/Documents/projects/deliveries/bin/rails:8:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/me/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.3/lib/active_support/dependencies.rb:268:in `load'
from /Users/me/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/me/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'2.2.2 :003 >
UPDATE Использование новой оболочки и подключения к консоли, казалось, магическим образом исправить положение. Я до сих пор не знаю, что изначально испорчены вещи, хотя ...
ум обмена вашего 'database.yml'? – nayiaw
Просьба поделиться файлом 'database.yml' и полной ошибкой стека ошибки. –
@nayiaw и kmrakibulislam обновлено – qix