0

After I run this migration, my geo_latitude and geo_longitude columns are type "float" (no precision and scale). I can run sql query directly and change the type to float(10, 6), so why does the migration ignore my precision and scale parameters?

def change
  add_column :item_exifs, :geo_latitude, :float, precision: 10, scale: 6, null: false, default: 0
  add_column :item_exifs, :geo_longitude, :float, precision: 10, scale: 6, null: false, default: 0
end
Anh Pham
  • 5,431
  • 3
  • 23
  • 27
  • why not use decimal ?, https://stackoverflow.com/questions/8514167/float-vs-decimal-in-activerecord – buncis Aug 03 '17 at 06:50
  • @icemelt because I don't need to be too precise of the location, and float is faster to do calculation. And I'm just curious if this is bug in migration or is it intended? – Anh Pham Aug 03 '17 at 06:51
  • see @rokibul hasan answer, he have problems with mysql and float and change it to decimal fix it for him, maybe also for you. – buncis Aug 03 '17 at 06:56
  • @icemelt Maybe that's the only option :) thank you – Anh Pham Aug 03 '17 at 07:38
  • ok I change my comment into answer then. – buncis Aug 03 '17 at 08:18

1 Answers1

3

try to change the type to decimal,

def change
  add_column :item_exifs, :geo_latitude, :decimal, precision: 10, scale: 6, null: false, default: 0
  add_column :item_exifs, :geo_longitude, :decimal, precision: 10, scale: 6, null: false, default: 0
end

some active record versions have several strange behavior based on the databases used

Float vs Decimal in ActiveRecord

see @Rokibul Hasan and @ryan0 answers

buncis
  • 2,148
  • 1
  • 23
  • 25