簡體   English   中英

根據db / schema.rb中的內容創建模型

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM