【问题标题】:rake migrate aborted for undefined local variable or methodrake 迁移因未定义的局部变量或方法而中止
【发布时间】:2013-04-12 19:20:24
【问题描述】:

运行 rake db:migrate 时遇到问题。错误信息是这样的

-- create_table(:addresses)
   -> 0.1792s
-- contact_id()
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined local variable or method `contact_id' for #<CreateAddresses:0x00000001724718>/var/lib/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/migration.rb:465:in `block in method_missing'

我在迁移之前使用了命令

rails g model address street:string city:string region:string postalcode:string country:string contact_id:integer

还有我的迁移文件:

class CreateAddresses < ActiveRecord::Migration
  def change
    create_table :addresses do |t|
      t.string :street
      t.string :city
      t.string :region
      t.string :postalcode
      t.string :country
      t.integer :contact_id

      t.timestamps
    end
    add_index :addresses, [contact_id, :create_at]
  end
end

谁能告诉我哪里出错了?非常感谢。

【问题讨论】:

    标签: ruby-on-rails-3 rails-migrations


    【解决方案1】:

    你在contact_id之前缺少:

    add_index :addresses, [:contact_id, :create_at]
    

    【讨论】:

    • aaa 非常感谢,但它现在告诉我 SQLite3::SQLException: table addresses has no column named create_at:
    猜你喜欢
    • 2017-06-27
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    相关资源
    最近更新 更多