2010-09-22 15 views
23

Raylar kullanarak yeni bir blog uygulaması yaratıldıKomisyon db sırasında fixnum dizeye dönüştürülemez: create

modelim basit:

class Post < ActiveRecord::Base 
    has_many :comments 
end 

class Comment < ActiveRecord::Base 
    belongs_to :post 
end 

Komutları kullandım: raylar iskele oluşturmak başlık: string body: text vs.

Dosyalar.

Şimdi db'yi kullanarak oluşturmak istedim:

rake db:

oluşturmak hatası aldım:

rake aborted! 
can't convert Fixnum into String 

Sorun ne olabilir?

** Invoke db:create (first_time) 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
** Execute db:create 
rake aborted! 
can't convert Fixnum into String 
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2/client.rb:36:in `connect' 
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2/client.rb:36:in `initialize' 
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `new' 
/Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `mysql2_connection' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `send' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `new_connection' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:238:in `checkout_new_connection' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:194:in `checkout' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `loop' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `checkout' 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in `checkout' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `connection' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in `retrieve_connection' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:68:in `create_database' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.0.0/lib/active_record/railties/databases.rake:33 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31 
/usr/bin/rake:19:in `load' 
/usr/bin/rake:19 

database.yaml:

# 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: myblog_development 
    pool: 5 
    username: root 
    password: 123 
    socket: /tmp/mysql.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: myblog_test 
    pool: 5 
    username: root 
    password: 123 
    socket: /tmp/mysql.sock 

production: 
    adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    database: myblog_production 
    pool: 5 
    username: root 
    password: 123 
    socket: /tmp/mysql.sock 

göçler: iz http://sixrevisions.com/web-development/how-to-create-a-blog-from-scratch-using-ruby-on-rails/

İşte edilir:

Bu öğretici takip ediyorum

class CreatePosts < ActiveRecord::Migration 
    def self.up 
    create_table :posts do |t| 
     t.string :title 
     t.text :body 

     t.timestamps 
    end 
    end 

    def self.down 
    drop_table :posts 
    end 
end 

sonraki geçiş:

class CreateComments < ActiveRecord::Migration 
    def self.up 
    create_table :comments do |t| 
     t.string :name 
     t.text :body 
     t.references :post 

     t.timestamps 
    end 
    end 

    def self.down 
    drop_table :comments 
    end 
end 
+0

bir backtrace var mı:

dize yorumunu zorlayarak çalışıyorsunuz? – Matchu

+0

Matchu --trace çıkışı ile güncellendi. – Blankman

+3

database.yml ve taşımanız neye benziyor? – sosborn

cevap

68

YAML ayrıştırıcı sizin database.yml dosyada her değer başka bağlamsal bilgi olmaksızın, ne veri türü tahmin etmek vardır. Bu nedenle, 123 değerinizin bir tam sayı olduğu düşünülmektedir.

password: "123" 
+1

Bunu düşünüyordum, ama kullanıcı adı neden çalışıyor? dize mi var? Bu düzeltmeyi bu gece deneyeceğim! – Blankman

+1

YAML ayrıştırıcısı, neye benzediğine bağlı olarak hangi veri türünün olduğunu tahmin eder. Yani, evet, 'root' muhtemelen başka bir veri türü olamayacağından, dizge olduğunu varsayar. – Matchu

+2

TEŞEKKÜR EDERİZ! Bu beni deli ediyordu. Tekrar bana iyilik yaptın :-) –

İlgili konular