创建模型时出错

时间:2013-04-12 10:55:45

标签: ruby-on-rails

创建模型时我在locale机器上遇到mysql错误

rails g model language name:string -e localdev


C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/client.rb:37:in `connect': Can't connect to MySQL server on 'jivestaging.cxrwdp0ae112.us-east-1.rds.amazon
s.com' (10060) (Mysql2::Error)
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/client.rb:37:in `initialize'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `new'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `mysql2_connection'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `new_connection'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:238:in `checkout_new_connection'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:194:in `block (2 levels) in checkout'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `loop'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in checkout'
        from C:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in `checkout'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `connection'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in `retrieve_connection'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/base.rb:596:in `quoted_table_name'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/history.rb:67:in `block in included'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/history.rb:63:in `instance_eval'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/history.rb:63:in `included'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/configuration.rb:60:in `include'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/configuration.rb:60:in `block in use'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/configuration.rb:58:in `map'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/configuration.rb:58:in `use'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/friendly_id-4.0.0/lib/friendly_id/base.rb:165:in `friendly_id'
        from D:/work/tibco-docs/app/models/product.rb:6:in `<class:Product>'
        from D:/work/tibco-docs/app/models/product.rb:3:in `<top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:227:in `load_dependency'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:346:in `require_or_load'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:491:in `load_missing_constant'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:183:in `block in const_missing'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:181:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:181:in `const_missing'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/inflector/methods.rb:124:in `block in constantize'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/inflector/methods.rb:123:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/inflector/methods.rb:123:in `constantize'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/core_ext/string/inflections.rb:43:in `constantize'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.0.0/lib/active_model/observing.rb:160:in `block in observe'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.0.0/lib/active_model/observing.rb:160:in `collect!'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.0.0/lib/active_model/observing.rb:160:in `observe'
        from D:/work/tibco-docs/app/models/auditor_observer.rb:2:in `<class:AuditorObserver>'
        from D:/work/tibco-docs/app/models/auditor_observer.rb:1:in `<top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:227:in `load_dependency'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:346:in `require_or_load'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:300:in `depend_on'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:216:in `require_dependency'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine.rb:138:in `block (2 levels) in eager_load!'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine.rb:137:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine.rb:137:in `block in eager_load!'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine.rb:135:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/engine.rb:135:in `eager_load!'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:108:in `eager_load!'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application/finisher.rb:41:in `block in <module:Finisher>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `instance_exec'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initializable.rb:25:in `run'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initializable.rb:50:in `block in run_initializers'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initializable.rb:49:in `each'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/initializable.rb:49:in `run_initializers'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:134:in `initialize!'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:77:in `method_missing'
        from D:/work/tibco-docs/config/environment.rb:8:in `<top (required)>'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/application.rb:103:in `require_environment!'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:16:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

我的本​​地环境是

localdev:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: tibcodocs_development
  pool: 5
  username: root
  password: root
  host: localhost

1 个答案:

答案 0 :(得分:0)

您应该在正确的环境中启动rails应用程序。

RAILS_ENV=localdev bundle exec rails g model language name:string -e localdev

(或者类似的东西,如果localdev不是你的开发模式)

目前它看起来像生产设置,因为您的应用程序试图联系亚马逊云或类似的东西(jivestaging.cxrwdp0ae112.us-east-1.rds.amazons.com)。

Windows版本:

set RAILS_ENV=localdev
bundle exec rails g model language name:string