运行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
请问有人告诉我哪里弄错了吗?非常感谢你。
答案 0 :(得分:2)
:
之前您遗失contact_id
:
add_index :addresses, [:contact_id, :create_at]