简体   繁体   中英

rails generate model failed

I'm following the tutorial from railstutorial.org so i decided to use mysql instead of sqlite but when I type in Terminal

rails generate model User name:string email:string

I get this error

    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>'

here's my database.yml file

# 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

and my GEMFILE

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

I'm using ruby 1.9.2p320 and Rails 3.0.12 on linux mint 16, maybe it's a silly error but I'm getting desperate.

# Gemfile
gem 'mysql2'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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