How do I create a rails migration to remove/change precision and scale on decimal?

后端 未结 2 695
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 11:54

I am trying to remove the precision and scale attributes from decimal (PostgreSQL NUMERIC) fields in my database?

The fields:

t.decimal          


        
相关标签:
2条回答
  • 2020-12-24 12:29

    format :

    change_column(table_name, column_name, type, options): Changes the column to a different type using the same parameters as add_column.
    

    First in you terminal:

    rails g migration change_numeric_field_in_my_table
    

    Then in your migration file:

    class ChangeNumbericFieldInMyTable < ActiveRecord::Migration
      def self.up
       change_column :my_table, :revenue_per_transaction, :decimal, :precision => give whatever, :scale => give whatever
      end
    end
    

    then

    run rake db:migrate
    

    Source : http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

    0 讨论(0)
  • 2020-12-24 12:33

    In your migration file change your field to :integer and run run rake db:migrate

    0 讨论(0)
提交回复
热议问题