# Rails 2.1 migrations default value problem

**URL:** <https://www.ruby-forum.com/t/rails-2-1-migrations-default-value-problem/140720>\
**Category:** Rails\
**Created:** [June 17, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/rails-2-1-migrations-default-value-problem/140720 "2008-06-17T23:13:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [June 17, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/rails-2-1-migrations-default-value-problem/140720/1 "2008-06-17T23:13:58Z")

</div>

I am using Rails 2.1 and mysql.

I have a very simple migration:

class CreateTasks \< ActiveRecord::Migration

def self.up  
create\_table :tasks do |t|  
t.column :job\_id, :integer, :null =\> false  
t.column :name, :string, :null =\> false  
t.column :description, :string  
t.column :actual, :number, :null =\> true  
end  
end

def self.down  
drop\_table :tasks  
end  
end

When I run this, the SQL that is generated is broken:

CREATE TABLE `tasks` (`id` int(11) DEFAULT NULL auto\_increment PRIMARY  
KEY, `name` varchar(255) NOT NULL, `description` varchar(255) DEFAULT  
NULL NULL, `actual` number DEFAULT NULL NULL) ENGINE=InnoDB

Note the DEFAULT NULL NULL, after the description and actual columns

- and also the default NULL after the id column which I don’t think  
should be there either - am I doing something totally stupid, or is  
something broken here?

I have used migrations successfully on Rails 1.x and 2.0 on this  
machine before OS X Tiger.

---

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [June 17, 2008, 11:26pm UTC](https://www.ruby-forum.com/t/rails-2-1-migrations-default-value-problem/140720/2 "2008-06-17T23:26:23Z")

</div>

On Jun 17, 10:13 pm, “stephen O’D” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> t.column :description, :string
> 
> ```
> 
> machine before OS X Tiger.  
> Seems I was doing something stupid - :number is not a correct column  
> type - changing it to :decimal sorts the problem. Definitely a  
> strange error though!

---

<div class="post-metadata">

**Author:** ![stephen\_OSD](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df788c/32.png) [@stephen\_OSD](https://www.ruby-forum.com/u/stephen_OSD)\
**Post date:** [June 17, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/rails-2-1-migrations-default-value-problem/140720/3 "2008-06-17T23:27:33Z")

</div>

Well, the new sexyosity is that you say instead:

t.integer :job\_id, :null =\> false

So–you call a method named after the datatype on the table block var,  
the first arg is the field name & other args get tacked on afterwards.

That said, I would have expected the older style to be supported  
still–and judging from the sql there it looks like it’s trying. Dunno.  
Someone here will tho, I don’t doubt…
