class User < ApplicationRecord
has_many :created_events, :foreign_key => "creator_id", :class_name => "Event"
end
class Event < ApplicationRecord
belongs_to :creator, :class_name => "User"
end
當我試圖用一個創造者創建一個事件,它說ActiveModel::UnknownAttributeError: unknown attribute 'creator_id' for Event.
我跑rails db:migrate
但仍不能創建外鍵,並添加到事件表。我究竟做錯了什麼?我到處看着。::加載ActiveModel UnknownAttributeError:未知屬性「creator_id」對事件
$軌分貝:遷移:狀態
Status Migration ID Migration Name
--------------------------------------------------
up 20170625163737 Create users
up 20170625170905 Create events
up 20170625171959 Add description to event
up 20170625174531 Add creator id to events
但是,遷移文件表明,沒有另外寫了:
class AddCreatorIdToEvents < ActiveRecord::Migration[5.1]
def change
end
end
什麼'軌分貝:遷移:status'回報? –
您是否可以使用遷移文件更新問題以創建事件表。你可以在'your_app/db/migrate'下找到它。 –
@SebastiánPalma補充說。 – sarpbasaraner