Change column in rails from integer to float -
i have contact_number in customers table using field integer. tried creating record in rails c apparently can't store larger field of numbers. looked around online think should use float instead of integer given precision of 10 numbers in states
my thought create new migration
class changecontactnumberincustomertabletofloatfrominteger < activerecord::migration def change_table remove_column :customers, :contact_number, :integer add_column :customers, :contact_number, :float end end
how specify precision , correct way in doing this?
first off, if correct contact_number
phone number, want use string rather numeric field. phone numbers not numeric values collection of digits. or stated more generally, collection of characters, happen limited numbers.
additionally, easier parse area code , country code too, if relevant (however hypothetically if need parse country , area code, you'd want store in separate columns anyways, that's different discussion)
to answer question directly, use change_column
method instead, so:
change_column :customers, :contact_number, :string
details found here: http://api.rubyonrails.org/classes/activerecord/migration.html
Comments
Post a Comment