最近我开始使用ruby on rails并坚持使用bin/rails generate model Article title:string text:text
,这应该创建model
两个columns
,不幸的是输出如下:
/usr/local/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777
/usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:284:in `block in visit_Psych_Nodes_Alias': Cannot load `Rails.application.database_configuration`:
Unknown alias: default1 (Psych::BadAlias)
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:284:in `fetch'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:284:in `visit_Psych_Nodes_Alias'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:5:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:31:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:302:in `block in revive_hash'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:300:in `each'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:300:in `each_slice'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:300:in `revive_hash'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:161:in `visit_Psych_Nodes_Mapping'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:5:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:31:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:302:in `block in revive_hash'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:300:in `each'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:300:in `each_slice'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:300:in `revive_hash'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:161:in `visit_Psych_Nodes_Mapping'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:5:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:31:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:276:in `visit_Psych_Nodes_Document'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/2.1.0/psych/visitors/visitor.rb:5:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/visitors/to_ruby.rb:31:in `accept'
from /usr/local/lib/ruby/2.1.0/psych/nodes/node.rb:37:in `to_ruby'
from /usr/local/lib/ruby/2.1.0/psych.rb:246:in `load'
from /usr/local/lib/ruby/gems/2.1.0/gems/railties-4.1.6/lib/rails/application/configuration.rb:99:in `database_configuration'
from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/railtie.rb:128:in `block (2 levels) in <class:Railtie>'
from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/base.rb:326:in `<module:ActiveRecord>'
from /usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.1.6/lib/active_record/base.rb:23:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:314:in `active_record_configured?'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:248:in `disconnect_database'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:97:in `preload'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /usr/local/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
有一些rvm特权问题,已通过以下方式解决:
sudo chmod -R 777 /usr/local/lib/ruby/2.1.0/
sudo chmod -R 777 /usr/local/
在generate model
之前,有sudo chmod o-w /usr/local/
。假设它们都不会影响上述问题。
欣赏任何解决方案。
修改
我没有运气地查找database_configuration
。我认为这个基本的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:
<<: *default1
database: db/production.sqlite3
答案 0 :(得分:3)
该特定环境缺少数据库配置。
如果给出了数据库详细信息。请确保database.yml中没有空格.Indentation应该是maintlying。单个额外空间可能会导致配置问题。