問題:
We have script/generate migration add_fieldname_to_tablename fieldname:datatype
syntax for adding new columns to a model.我們有script/generate migration add_fieldname_to_tablename fieldname:datatype
語法用於向模型添加新列。
On the same line, do we have a script/generate for changing the datatype of a column?在同一行,我們是否有用於更改列數據類型的腳本/生成? Or should I write SQL directly into my vanilla migration?或者我應該將 SQL 直接寫入我的 vanilla 遷移中嗎?
I want to change a column from datetime
to date
.我想將一列從datetime
更改爲date
。
解決方案:
參考一: https://stackoom.com/question/BkLe參考二: Rails migration for change column