我創建了一個腳本,用於在另一個數據庫中填充新表,因爲我將此表從一個數據庫(table_1)中移出並且到另一個數據庫(db_2)中。我已經在新的數據庫(db_2)中創建了'new_geo_fence'表,並希望讓腳本在下面運行以遷移數據。下面的腳本:Rails 4腳本+錯誤:將數據從一個表遷移到另一個
class NewGeoFence < ActiveRecord::Base
attr_accessible :name, :address, :latitude, :longitude, :radius, :customer_id
belongs_to :customer, :foreign_key => 'customer_id'
end
require 'rubygems'
GeoFence.all.each do |g|
gf = NewGeoFence.new(
:id => g.id,
:name => g.name,
:address => g.address,
:latitude => g.latitude,
:longitude => g.longitude,
:radius => g.radius,
:created_at => g.created_at,
:updated_at => g.updated_at,
:customer_id => g.customer_id
)
gf.save
end
然而,當我運行它,我得到這個錯誤:
/activerecord-4.0.13/lib/active_record/attribute_assignment.rb:47:in `rescue in _assign_attribute': unknown attribute: customer_id (ActiveRecord::UnknownAttributeError)
有什麼我錯過了得到這個腳本運行?
謝謝!