Rails 2.0.2 MySQL 'year' datatype missing from ActiveRecord?

Hi all,

This is my first post to the forum, and I'll point out right away that
I'm a noob to everything, Ruby, Rails, MySQL, etc., so I expect that I'm
wrong here, but is the 'year' datatype missing from ActiveRecord in
2.0.2? According to my MySQL 5.0 reference manual, 'year' is a datatype,
but when I try to run a migration that has a t.year column, I get this:

rake aborted!
undefined method `year' for
#<ActiveRecord::ConnectionAdapters::TableDefinition:0x274a070>

I opened up the mysql_adapter.rb file in my frozen 2.0.2 ActiveRecord,
and sure enough, 'year' was missing from the native_database_types hash,
so I added it. rake db:migrate still doesn't work (continues to give the
same error, and I can't find the TableDefinition), however. Any
suggestions? I can of course use a 'date' as a workaround, but I'm
building a discography, and 'year' is all I need.

Thanks,
Tom

Hi all,

This is my first post to the forum, and I'll point out right away that
I'm a noob to everything, Ruby, Rails, MySQL, etc., so I expect that I'm
wrong here, but is the 'year' datatype missing from ActiveRecord in
2.0.2? According to my MySQL 5.0 reference manual, 'year' is a datatype,
but when I try to run a migration that has a t.year column, I get this:

rake aborted!
undefined method `year' for
#<ActiveRecord::ConnectionAdapters::TableDefinition:0x274a070>

why not use an integer?

This is my first post to the forum, and I'll point out right away that
I'm a noob to everything, Ruby, Rails, MySQL, etc., so I expect that I'm
wrong here, but is the 'year' datatype missing from ActiveRecord in
2.0.2? According to my MySQL 5.0 reference manual, 'year' is a datatype,
but when I try to run a migration that has a t.year column, I get this:

rake aborted!
undefined method `year' for
#<ActiveRecord::ConnectionAdapters::TableDefinition:0x274a070>

I opened up the mysql_adapter.rb file in my frozen 2.0.2 ActiveRecord,
and sure enough, 'year' was missing from the native_database_types hash,
so I added it. rake db:migrate still doesn't work (continues to give the
same error, and I can't find the TableDefinition), however. Any
suggestions? I can of course use a 'date' as a workaround, but I'm
building a discography, and 'year' is all I need.

I don't believe that 'year' is a standard sql type so I suspect that Rails is intentionally not putting it in there as what you've just done won't work with other databases...

If all you need is the number, just make it an :integer.

-philip

Something similar happens with the DB2 XML data type.

I described the problem here: http://leonardoborges.com/writings/2008/01/02/rails-20-xml-data-type-and-db2/

The bottom line is that the sexy migrations doesn't work with the xml
data type.

So instead of:

t.xml :column_name

I had to do:

t.column :data, :xml

thus making use of the old syntax.

It might work in your case as well. Give it a try.

Hope this helps

Thanks, this makes sense. I agree that an integer is the way to go,
but I figured that if it existed in MySQL I might as well use it. But
if it's specific only to MySQL, then I understand why it's not there.
Is there a place in the API/docs where this kind of stuff is listed/
explained?

Thanks, this makes sense. I agree that an integer is the way to go,
but I figured that if it existed in MySQL I might as well use it. But
if it's specific only to MySQL, then I understand why it's not there.
Is there a place in the API/docs where this kind of stuff is listed/
explained?

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#M001222