6

我正在关注RoR 入门教程。创建帖子后,我现在添加第二个模型来创建评论。但是,当我尝试 rake 时,db:migrate我得到了这个:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
==  CreateComments: migrating =================================================
-- create_table(:comments)
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `reference' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x1084a24d8>
/Users/Fryed/rails/blog/db/migrate/20120710225337_create_comments.rb:6:in `change'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/schema_statements.rb:160:in `create_table'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:466:in `send'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:466:in `method_missing'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:438:in `say_with_time'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:438:in `say_with_time'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:458:in `method_missing'
/Users/Fryed/rails/blog/db/migrate/20120710225337_create_comments.rb:3:in `change'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:407:in `migrate'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:407:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:123:in `with_connection'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:389:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:528:in `__send__'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:528:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:720:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:775:in `call'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:775:in `ddl_transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/transactions.rb:208:in `transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:775:in `ddl_transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:719:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:700:in `each'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:700:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:570:in `up'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/migration.rb:551:in `migrate'
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.6/lib/active_record/railties/databases.rake:153
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:158: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.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2.2/bin/rake:33
/usr/bin/rake:23:in `load'
/usr/bin/rake:23
Tasks: TOP => db:migrate

我在跑:

耙 0.9.2.2。红宝石 1.8.7 轨道 3.2.6

4

1 回答 1

21

带有引用的迁移使用references帮助器,您可能只是忘记将 thes放在最后。

找到有问题的迁移db/migrate/20120710225337_create_comments.rb并从 更改referencereferences

于 2012-07-11T15:12:31.367 回答