Rails migration for change column

后端 未结 9 1061
一个人的身影
一个人的身影 2020-11-28 17:24

We have script/generate migration add_fieldname_to_tablename fieldname:datatype syntax for adding new columns to a model.

On the same line, do we have a

9条回答
  •  时光取名叫无心
    2020-11-28 18:09

    Another way to change data type using migration

    step1: You need to remove the faulted data type field name using migration

    ex:

    rails g migration RemoveFieldNameFromTableName field_name:data_type
    

    Here don't forget to specify data type for your field

    Step 2: Now you can add field with correct data type

    ex:

    rails g migration AddFieldNameToTableName field_name:data_type
    

    That's it, now your table will added with correct data type field, Happy ruby coding!!

提交回复
热议问题