-1

Rails 3.2 を使用して、開発データベースとして mysql を使用して Rails アプリを構築しています。しかし、rake db:migrate を実行すると、以下のエラーが発生しました。Fixnum to string のエラーについては、多くの人がパスワードが数字だからだと言っていますが、私のパスワードはすでに文字列です。エラーが発生するステップがわかりません。

助けてください。

ここに私のdatabase.ymlがあります

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: nwapp_development
pool: 5
username: root
password: mysqlroot
host: 3306

これが私の rake db:create --trace エラーです

$ rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:create
rake aborted!
can't convert Fixnum into String
c:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `initialize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:106:in `rescue in create_database'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:74:in `create_database'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:62:in `each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:227:in `call'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:227:in `block in execute'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:222:in `each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:222:in `execute'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:159:in `invoke_with_call_chain'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:152:in `invoke'

c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:141:in `invoke_task'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `block (2 levels) in top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `block in top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:108:in `run_with_threads'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:93:in `top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:71:in `block in run'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exception_handling'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:68:in `run'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/bin/rake:37:in `<top (required)>'
c:/Ruby193/bin/rake:23:in `load'
c:/Ruby193/bin/rake:23:in `<main>'
Tasks: TOP => db:create

更新 1:

これが更新されたdatabase.ymlです

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: nwapp_development
pool: 5
username: root
password: mysqlroot
host: localhost
port: 3306

これは、ポートの追加とホストの変更の結果です

$ rake db:create
Can't connect to MySQL server on 'localhost' (10061)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"nwapp_development", "pool"=>5, "username"=>"root", "password"=>"mysqlroot", "host"=>"localhost", "port"=>3306}, charset: utf8, collation:
(if you set the charset manually, make sure you have a matching collation) 
Can't connect to MySQL server on 'localhost' (10061)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"nwapp_test", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost"}, charset: utf8, collation:
(if you set the charset manually, make sure you have a matching collation)

更新 2:

mysql サーバーでデータベースを手動で作成する必要があります。

ここに私のdatabase.ymlがあります

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: nwapp_development
pool: 5
username: root
password: mysqlroot
host: 127.0.0.1
port: 3306
4

1 に答える 1

0

mu のコメントを展開すると、 orhost: 3306のようなものに変更する必要があります。host: localhosthost: 127.0.0.1

3306 は mySQL 通信のデフォルト ポートであるため、明示的に設定する必要はありません。それでも必要な場合port: 3306は、database.yml に含めることができます

于 2012-12-02T07:09:35.287 に答える