简体   繁体   English

rake db:migrate UNEXPECTED错误

[英]rake db:migrate UNEXPECTED error

Hello pls help with an unexpected error when I run my rails app. 您好,当我运行Rails应用程序时遇到意外错误,请提供帮助。 rake db:migrate then there is an error rake db:migrate然后出现错误

CreateTodoItems: migrating ==================================
-- create_table(:todo_items)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `reference' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x007f9d9c981ed0>/Users/chenziwang/odot/db/migrate/20150421184553_create_todo_items.rb:4:in `block in change'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:202:in `create_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:662:in `block in method_missing'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `block in say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:632:in `say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:652:in `method_missing'
/Users/chenziwang/odot/db/migrate/20150421184553_create_todo_items.rb:3:in `change'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:606:in `exec_migration'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:589:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:588:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:765:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/transactions.rb:220:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:1041:in `ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:956:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:952:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:952:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:820:in `up'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/migration.rb:798:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

my migrate files are: 我的迁移文件是:

class CreateTodoLists < ActiveRecord::Migration
  def change
    create_table :todo_lists do |t|
      t.string :title
      t.text :description

      t.timestamps null: false
    end
  end
end

Another file is 另一个文件是

class CreateTodoItems < ActiveRecord::Migration
  def change
    create_table :todo_items do |t|
      t.reference :todo_list
      t.string :content

      t.timestamps null: false
    end
  end
end

In your second migration you've got t.reference :todo_list , that's wrong. 在第二次迁移中,您有t.reference :todo_list ,这是错误的。 You should have t.references :todo_list . 您应该具有t.references :todo_list Plural. 复数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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