[英]Creating models based on what's in db/schema.rb
我在db/schema.rb
有這個:
create_table "bank", :force => true do |t|
t.string "name", :null => false
t.string "identifier", :null => false
t.timestamp "created_at", :null => false
t.timestamp "updated_at", :null => false
end
有沒有一種簡單的方法可以基於此創建模型? 我不想手動輸入
rails generate model Bank name:string identifier:string
因為我的數據庫中有大約40個表,許多表的列比這多得多。
這可能嗎?
您是否正在嘗試回溯以從現有db/schema.rb
獲取模型和遷移?
schema.rb
應該是遷移的結果,並且您實際上不需要為模型做任何事情,因為您要做的就是創建一個從ActiveRecord::Base
繼承的類。
換句話說,在rails generate model Bank name:string identifier:string
指定列會rails generate model Bank name:string identifier:string
只是為您創建遷移,而在模型文件中沒有這些屬性的概念。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.