Rails think db column is integer when it is a float

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

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!

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.