Hi, I came across the strangest issue I have no idea how it happened. In my development environment, I created a new migration and model that uses a couple of decimal column types (among others). Everything works great with sqlite and the development environment, business as usual. However, I deployed to production and for some completely unknown reason, this particular table (only this one) shows up with "integer" column types. To clarify, when I investigate the MYSQL db in production, MYSQL shows that the columns are decimal types. However, when type in the model class name into the production console, it shows the column types as integer. This is a problem for me because it''s holding prices, so I''m losing my cents (no pun intended). How does rails determine the column types? The migration shows decimal column types, by the way. Thanks to anyone that has any insight. Nick -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ignore my plea. It turns out I have the wrong precision on the table columns. Even though they were indeed decimals, rails saw the 0 scale on the table column and thought that they were integers. Dang, that''s a gotcha! On Jan 12, 1:25 pm, Precisio <burdick...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I came across the strangest issue I have no idea how it happened. In > my development environment, I created a new migration and model that > uses a couple of decimal column types (among others). Everything > works great with sqlite and the development environment, business as > usual. However, I deployed to production and for some completely > unknown reason, this particular table (only this one) shows up with > "integer" column types. > > To clarify, when I investigate the MYSQL db in production, MYSQL shows > that the columns are decimal types. However, when type in the model > class name into the production console, it shows the column types as > integer. This is a problem for me because it''s holding prices, so I''m > losing my cents (no pun intended). > > How does rails determine the column types? The migration shows > decimal column types, by the way. > > Thanks to anyone that has any insight. > Nick-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Robert Walker
2012-Jan-12 21:45 UTC
Re: Rails think db column is integer when it is a float
Precisio wrote in post #1040594:> Ignore my plea. It turns out I have the wrong precision on the table > columns. Even though they were indeed decimals, rails saw the 0 scale > on the table column and thought that they were integers. Dang, that''s > a gotcha!This is why I always specify precision and scale in my migrations: t.decimal :price, :precision => 10, :scale => 2 This removes any confusion between the migration and database schema. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.