AUTHORS
CATEGORIES
- Airsoft (2)
- Austin (8)
- Books (9)
- Cooking For Engineers (20)
- Credit Cards (2)
- Current Events (9)
- Deals (4)
- Dining (37)
- Fanpop (4)
- Food (808)
- Games (5)
- Hairy (6)
- Kitchen Gear (7)
- Life (24)
- Miscellaneous (6)
- Movies (15)
- Orthogonal Thought (6)
- Personal Computers (10)
- Photography (158)
- Rant (9)
- Ruby on Rails (2)
- San Francisco (5)
- Soap Making (5)
- Television (11)
- Texas (1)
- Things We Like (11)
- Travel (11)
- Wear or Not (1)
- Web 2.0 (9)
- What I Ate (861)
- Wikipedia (5)
- Windows 10 (3)
- Windows Mobile (1)
- WordPress (1)
ARCHIVE
- September 2018 (1)
- September 2017 (1)
- March 2017 (1)
- September 2016 (2)
- August 2016 (2)
- September 2015 (1)
- November 2014 (1)
- August 2014 (1)
- January 2014 (1)
- September 2013 (1)
- December 2012 (1)
- November 2012 (3)
- September 2012 (1)
- August 2012 (2)
- June 2012 (2)
- February 2012 (1)
- January 2012 (4)
- December 2011 (4)
- October 2011 (2)
- September 2011 (5)
- August 2011 (1)
- July 2011 (2)
- April 2011 (2)
- February 2011 (5)
- January 2011 (12)
- December 2010 (37)
- November 2010 (30)
- October 2010 (25)
- September 2010 (30)
- August 2010 (32)
- July 2010 (34)
- June 2010 (31)
- May 2010 (35)
- April 2010 (35)
- March 2010 (33)
- February 2010 (34)
- January 2010 (33)
- December 2009 (30)
- November 2009 (31)
- October 2009 (30)
- September 2009 (31)
- August 2009 (34)
- July 2009 (34)
- June 2009 (34)
- May 2009 (33)
- April 2009 (32)
- March 2009 (42)
- February 2009 (38)
- January 2009 (57)
- December 2008 (40)
- November 2008 (30)
- October 2008 (33)
- September 2008 (22)
- August 2008 (5)
- July 2008 (5)
- June 2008 (11)
- May 2008 (13)
- April 2008 (10)
- March 2008 (29)
- February 2008 (18)
- January 2008 (28)
- December 2007 (1)
- November 2007 (4)
- October 2007 (5)
- September 2007 (10)
- August 2007 (14)
- July 2007 (10)
- June 2007 (9)
- May 2007 (21)
- April 2007 (21)
MySQL and Ruby on Rails datatypes
Posted 29 June, 2007 at 12:36pm by Michael Chu(Filed under: Ruby on Rails, Web 2.0)
One of the best features of Ruby on Rails is the ability to interact with database tables as objects using ActiveRecord. Sometimes documentation can be a bit spotty, but after searching for a little bit it's not hard to find the mapping from Rails Migration types to MySQL data types. I did find it more difficult to find out what happens if I already have an existing MySQL table. What Ruby class gets created with what MySQL column type? I didn't find it on the web, so I put together this list…
I added links to MySQL documentation for each of the MySql data types and links to the relevant Ruby class type to make this table a bit more useful.
MySQL Column Data Type to Ruby class type (when using ActiveRecord)
For completeness sake, here's a summary of Rails migration types and their MySQL column data types.
Rails Migration Type to MySQL Column Data Type
Rails Migration Symbol | MySQL Data Type |
---|---|
:binary | blob |
:boolean | tinyint(1) |
:date | date |
:datetime | datetime |
:decimal | decimal |
:float | float |
:integer | int(11) |
:string | varchar(255) |
:text | text |
:time | time |
:timestamp | datetime |
11 comments to MySQL and Ruby on Rails datatypes
Free as in Time » Blog Archive » RoR Tuesday 03/07/2007, July 11th, 2007 at 8:37 am:
-
[…] MySQL and Ruby on Rails datatypes - Sweet resource. One of the best features of Ruby on Rails is the ability to interact with database tables as objects using ActiveRecord. Sometimes documentation can be a bit spotty, but after searching for a little bit it’s not hard to find the mapping from Rails Migration types to MySQL data types. I did find it more difficult to find out what happens if I already have an existing MySQL table. What Ruby class gets created with what MySQL column type? I didn’t find it on the web, so I put together this list… […]
viktor, August 30th, 2007 at 4:28 am:
-
This is nice, but it seems like a flaw that Ruby on rails is incapable of managing the "double" data type..
I know that there is a patch avaliable: http://dev.rubyonrails.org/ticket/7594 .
Will that ever be a part of the standard RoR package ?
Tipos de datos Ruby on Rails a MySQL « Leobrambilla Weblog, August 30th, 2007 at 1:31 pm:
-
[…] Esta es una info que me costo un poco encontrar por eso la comparto. Son los datos a cargar en el Modelo generado por […]
links for 2008-03-24 « Web Flakes, March 23rd, 2008 at 8:17 pm:
-
[…] MySQL and Ruby on Rails datatypes (tags: rails.datatypes) […]
digital subterfuge » Blog Archive » Apples and Oranges. Er, RoR and MySQL data types., May 12th, 2008 at 10:09 pm:
-
[…] This site has a handy chart to tell you. […]
Anonymous, March 17th, 2009 at 7:57 am:
-
good job!
Migrar una base de datos localizada con Ruby on Rails « Constructor sobrecargado, August 30th, 2009 at 2:04 am:
-
[…] MySQL and Ruby on Rails datatypes […]
TNT, October 25th, 2009 at 5:35 am:
-
VERY IMPORTANT FOR CURRENCIES AND SIMILIAR:
The decimal type is only mapped to Fixnum if :scale => 0 (which is the default). But if :scale is > 0 decimal is mapped to BigDecimal which is what we need for computations without the Float rounding errors.
Flex For Rails Scaffold | Softarama Labs, October 11th, 2010 at 3:27 pm:
-
[…] (data types with Ruby and mySQL) […]
Visoft, Inc. Blogs | Rails 101 – Rails 01, April 24th, 2011 at 7:50 am:
-
[…] http://www.orthogonalthought.com/blog/index.php/2007/06/mysql-and-ruby-on-rails-datatypes/ This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL. Damien White is a developer in Connecticut that simply loves coding. Ever since he was young, he has had a driving passion for computers and software development, and a thirst for knowledge that just cannot be quenched. He’s happy to share what he knows in his quest to learn as much as possible. « Entity Framework – Removing Foreign Keys from the Entity Model […]
Rails – Tipos de dados do ActiveRecord « RacionalRubyRails, May 19th, 2011 at 6:05 am: