# Rails 2.0.2 MySQL 'year' datatype missing from ActiveRecord?

**URL:** <https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240>\
**Category:** Rails\
**Created:** [February 26, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240 "2008-02-26T18:03:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [February 26, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240/1 "2008-02-26T18:03:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [February 26, 2008, 6:36pm UTC](https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240/2 "2008-02-26T18:36:46Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [February 26, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240/3 "2008-02-26T18:44:59Z")

</div>

Something similar happens with the DB2 XML data type.

I described the problem here:

> **[rails 20 xml data type and db2](http://leonardoborges.com/writings/2008/01/02/rails-20-xml-data-type-and-db2/)**
>
> \[2008/04/30\] Update: The ibm\_db gem has been updated to support the new Rails 2.0 style migration. Now you can just use t.xml and it will work. Look here for more info. Thanks to Mario Briggs for pointing me to the update.
> \---
> In my new job we work...

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

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [February 26, 2008, 6:53pm UTC](https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240/4 "2008-02-26T18:53:48Z")

</div>

On 26 Feb 2008, at 17:03, Tom Simon wrote:

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

why not use an integer?

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [February 27, 2008, 2:44am UTC](https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240/5 "2008-02-27T02:44:37Z")

</div>

> 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?

> **[ActiveRecord::ConnectionAdapters::TableDefinition](https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#M001222)**
>
> Represents the schema of an SQL table in an abstract way. This class provides methods for manipulating the schema representation.

---

<div class="post-metadata">

**Author:** ![tomx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@tomx](https://www.ruby-forum.com/u/tomx)\
**Post date:** [February 27, 2008, 12:57am UTC](https://www.ruby-forum.com/t/rails-2-0-2-mysql-year-datatype-missing-from-activerecord/130240/6 "2008-02-27T00:57:24Z")

</div>

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?
