# Migrations with :decimal

**URL:** <https://discuss.rubyonrails.org/t/migrations-with-decimal/1435>\
**Category:** rubyonrails-talk\
**Created:** [September 11, 2006, 2:08pm UTC](https://discuss.rubyonrails.org/t/migrations-with-decimal/1435 "2006-09-11T14:08:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isak](https://avatars.discourse-cdn.com/v4/letter/i/ac91a4/32.png) [@Isak](https://discuss.rubyonrails.org/u/Isak)\
**Post date:** [September 11, 2006, 2:08pm UTC](https://discuss.rubyonrails.org/t/migrations-with-decimal/1435/1 "2006-09-11T14:08:03Z")

</div>

I have the following migration:

class TestMigration \< ActiveRecord::Migration &nbsp;&nbsp;def self.up &nbsp;&nbsp;&nbsp;&nbsp;create\_table :apples do |t| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column :name, :string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column :qty, :decimal, :precision =\> 16, :scale =\> 2 &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;add\_column :apples, :amt, :decimal, :precision =\> 16, :scale =\> 2 &nbsp;&nbsp;end

&nbsp;&nbsp;def self.down &nbsp;&nbsp;&nbsp;&nbsp;drop\_table :apples &nbsp;&nbsp;end end

Which yields this db structure:

CREATE TABLE apples ( &nbsp;&nbsp;id serial NOT NULL, &nbsp;&nbsp;name varchar(255), &nbsp;&nbsp;qty numeric(16,2), &nbsp;&nbsp;amt numeric, &nbsp;&nbsp;CONSTRAINT apples\_pkey PRIMARY KEY (id) );

Is my add\_column statement wrong, or is there a bug somewhere? Running latest edge -- 5086.

Any feedback appreciated, Isak

---

<div class="post-metadata">

**Author:** ![Francois\_Montel](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@Francois\_Montel](https://discuss.rubyonrails.org/u/Francois_Montel)\
**Post date:** [September 11, 2006, 3:09pm UTC](https://discuss.rubyonrails.org/t/migrations-with-decimal/1435/2 "2006-09-11T15:09:04Z")

</div>

I haven’t found :decimal to work for me. Use the following in your migration (outside the create table loop).

```
execute "ALTER TABLE apples ADD COLUMN amt DECIMAL(16,2)"

```

---

<div class="post-metadata">

**Author:** ![Isak](https://avatars.discourse-cdn.com/v4/letter/i/ac91a4/32.png) [@Isak](https://discuss.rubyonrails.org/u/Isak)\
**Post date:** [September 11, 2006, 8:33pm UTC](https://discuss.rubyonrails.org/t/migrations-with-decimal/1435/3 "2006-09-11T20:33:29Z")

</div>

Thank you, but I should have been a little clearer.

Edge rails does support decimal columns, I'm trying to figure out what goes wrong in my migration.

Is it my code that's wrong, my environment, or a bug in rails?

I just ran the same migration for sqlite, with different results:

CREATE TABLE apples ("id" INTEGER PRIMARY KEY NOT NULL, "name" varchar(255), "qty" decimal, "amt" decimal(16,2));

Now amt has precision/scale, while qty doesn't..

Isak
