1
我想創建以下並明確設置is_seen爲false。創建導軌模型時如何設置默認值
rails g model notification body: text, user_id: integer, is_seen: boolean
我知道如何通過change_column更新此更改,但是如何在此時將其設置爲false?
THX
- 不是爲遷移,但是從創建模型
我想創建以下並明確設置is_seen爲false。創建導軌模型時如何設置默認值
rails g model notification body: text, user_id: integer, is_seen: boolean
我知道如何通過change_column更新此更改,但是如何在此時將其設置爲false?
THX
- 不是爲遷移,但是從創建模型
同時創建該點的模型/遷移不能設置默認值。
你必須創建/編輯遷移文件,並更改相應的線路是這樣的:
add_column :table, :is_seen, :boolean, default: false
的[我可以通過默認值軌道產生遷移?](HTTP可能重複:// stackoverflow.com/questions/24565589/can-i-pass-default-value-to-rails-generate-migration) – MarsAtomic