Migrations with :decimal

I have the following migration:

class TestMigration < ActiveRecord::Migration
def self.up
create_table :apples do |t|
t.column :name, :string
t.column :qty, :decimal, :precision => 16, :scale => 2
end
add_column :apples, :amt, :decimal, :precision => 16, :scale => 2
end

def self.down
drop_table :apples
end
end

Which yields this db structure:

CREATE TABLE apples
(
id serial NOT NULL,
name varchar(255),
qty numeric(16,2),
amt numeric,
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

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)"

On 9/11/06, Isak H. [email protected] wrote:

add_column :apples, :amt, :decimal, :precision => 16, :scale => 2

CREATE TABLE apples
latest edge – 5086.

Any feedback appreciated,
Isak


“Impossible is nothing.”

On 9/11/06, zer0halo [email protected] wrote:

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)"

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