繁体   English   中英

Rails生成模型失败

[英]rails generate model failed

我正在关注railstutorial.org上的教程,因此我决定使用mysql代替sqlite,但是当我输入Terminal时

rails生成模型用户名:string电子邮件:string

我得到这个错误

    invoke  active_record
    /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activerecord-3.0.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in `establish_connection': development database is not configured (ActiveRecord::AdapterNotSpecified)
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activerecord-3.0.12/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activerecord-3.0.12/lib/active_record/railtie.rb:59:in `block (2 levels) in <class:Railtie>'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/lazy_load_hooks.rb:42:in `each'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activerecord-3.0.12/lib/active_record/base.rb:1910:in `<top (required)>'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/railties-3.0.12/lib/rails/generators/named_base.rb:97:in `pluralize_table_names?'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/railties-3.0.12/lib/rails/generators/named_base.rb:44:in `table_name'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activerecord-3.0.12/lib/rails/generators/active_record/model/model_generator.rb:16:in `create_migration_file'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:109:in `invoke'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/group.rb:269:in `block in _invoke_for_class_method'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/shell.rb:74:in `with_padding'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/group.rb:258:in `_invoke_for_class_method'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/group.rb:150:in `_invoke_from_option_orm'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/railties-3.0.12/lib/rails/generators.rb:163:in `invoke'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/railties-3.0.12/lib/rails/commands/generate.rb:10:in `<top (required)>'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/dependencies.rb:242:in `require'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/dependencies.rb:242:in `block in require'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/dependencies.rb:225:in `block in load_dependency'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/dependencies.rb:597:in `new_constants_in'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/dependencies.rb:225:in `load_dependency'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/activesupport-3.0.12/lib/active_support/dependencies.rb:242:in `require'
            from /home/sanchez/.rvm/gems/ruby-1.9.2-p320@rails3tutorial/gems/railties-3.0.12/lib/rails/commands.rb:17:in `<top (required)>'
            from script/rails:6:in `require'
            from script/rails:6:in `<main>'

这是我的database.yml文件

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql2
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: ProjectName_development
pool: 5
username: root
password: ***
socket: /var/run/mysqld/mysqld.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
reconnect: false
database: ProjectName_test
pool: 5
username: root
password: ***
socket: /var/run/mysqld/mysqld.sock

production:
adapter: mysql2
encoding: utf8
reconnect: false
database: ProjectName_production
pool: 5
username: root
password: ***
socket: /var/run/mysqld/mysqld.sock

和我的GEMFILE

source 'http://rubygems.org'
gem 'rails', '3.0.12'
gem 'mysql2', '~> 0.2.17'

我在Linux Mint 16上使用ruby 1.9.2p320和Rails 3.0.12,也许这是一个愚蠢的错误,但是我却绝望了。

# Gemfile
gem 'mysql2'

# config/database.yml
development:
  adapter: mysql2
  encoding: utf8
  database: projectName_development
  pool: 5
  username: root
  password: "123"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM