我想從做seller_id在遷移添加到我的項目模型如下:Rails遷移t.belongs_to:user,添加自定義列名seller_id?
rails g model Item title:string description:text price:bigint status:integer published_date:datetime seller:belongs_to
這並沒有當然的工作...
最終我想看看seller_id在我的項目表,它將項目模型與用戶模型相關聯。
目前我的移民是這樣的:
class CreateItems < ActiveRecord::Migration
def change
create_table :items do |t|
t.string :title
t.text :description
t.bigint :price
t.integer :status
t.datetime :published_date
t.belongs_to :user, index: true, foreign_key: true
t.timestamps null: false
end
end
end
如何修改這個遷移創建一個外鍵「seller_id」,涉及到用戶模型。
如何從控制檯自動生成包含來自1.的編輯的遷移? I.E修改rails g模型...以生成我需要的遷移。
非常感謝!
不錯的答案,謝謝! – matthewalexander