Orthogonal Thought | Random musings from the creator of Cooking For Engineers and Lead Architect of Fanpop





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)

MySQL Data Type Empty Ruby Class Ruby Class
bigint NilClass Bignum
binary String String
blob String String
bool NilClass TrueClass
char String String
date NilClass Date
datetime NilClass Time
decimal NilClass Fixnum
double NilClass Float
enum String String
float NilClass Float
int NilClass Bignum
longblob String String
longtext String String
mediumblob String String
mediumint NilClass Fixnum
mediumtext String String
set NilClass String
smallint NilClass Fixnum
text String String
time NilClass Time
timestamp NilClass Time
tinyblob String String
tinyint NilClass Fixnum
tinyint(1) NilClass TrueClass
tinytext String String
varbinary String String
varchar String String
year NilClass String

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

37 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:


    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:

How to: Rails 3 datatypes? | SevenNet, December 11th, 2014 at 6:37 am:

Answer: Rails 3 datatypes? #it #computers #programming | Good Answer, January 2nd, 2015 at 11:55 pm:

Solution: Rails 3 datatypes? #development #programming #it | IT Info, January 13th, 2015 at 8:26 am:

travel the world 2016, March 17th, 2016 at 4:09 am:

  • Thank you for some other magnificent post. Where else could
    anybody get that type of info in such an ideal approach of writing?
    I've a presentation next week, and I'm at the search for such info.

Noble, April 28th, 2016 at 12:32 am:

  • A physician will base a medical diagnosis on information you supply and on physical exam The characteristic appearance
    of the herpes sores leaves little doubt.

www.mycityfaces.com, April 28th, 2016 at 7:49 pm:

  • We focs on building and also mounting all your
    personalized shed kits, http://www.mycityfaces.com,
    as well as outdoors storage spae buildings in a variety of designs, designs and sizes to mattch any

Adrianne, May 2nd, 2016 at 9:38 am:

  • When a patient has herpes, he can have one of 2 stress of the virus: type 1 or type 2.
    Not everyone who ends up being exposed to a herpes simplex virus will display

Toko Online Terpercaya Di Indonesia, May 3rd, 2016 at 3:28 pm:

  • Oh my goodness! Impressive article dude! Thank you, However I am having troubles with your RSS.

    I don't understand why I am unable to join it.

    Is there anyone else getting similar RSS problems?
    Anyone that knows the answer will you kindly respond?

Shawn, July 20th, 2016 at 9:19 am:

  • Of course, to avoid the spread of the disease, infected
    persons experiencing an outbreak ought to likewise avoid contacting others with the
    infected area of skin through kissing or oral sex, and they
    should wash their hands with soap and warm water after touching any skin locations impacted by oral

howtoattractawoman16.beep.com, October 28th, 2016 at 5:04 am:

  • He doesn't do anything but sitting in the space
    thinking about his ex sweetheart who has actually already left him.

http://grandcru88.se/favicon.asp, October 29th, 2016 at 11:21 pm:

  • You actually make it appear really easy along with your presentation however I to find this matter to be really one thing which I think I would by no means understand. It kind of feels too complex and extremely huge for me. I am having a look forward for your next submit, Iˇll attempt to get the grasp of it!

Chloe, November 7th, 2016 at 12:10 am:

  • Small red bumps in the genital or anal area are the most typical sign of a herpes

gul.ly, December 25th, 2016 at 8:59 am:

  • When challenged with the HSV-2 virus for approximately one week
    after being offered the siRNA, the cured mice were still secured.
    This can be heated up in the microwave. The present study took a look at a
    subgroup of women who 'd participated in the larger trial testing tenofovir
    gel versus HIV. Compared to HIV, liver disease C infection is most likely to still be unacknowledged at the time
    of a person's death. If this same damage happened internally, cold sores could be
    a danger to your life. Transmission can happen from a contaminated partner who does not have a noticeable sore and
    may not know that he or she is contaminated. Circumcision appears to
    be on the decline in the United States (a 2005 Agency for Healthcare Research and Quality research study
    put the rate at about 56 percent), however the practice
    has cultural and long religious roots. We have actually been on 4 dates in the past 10 days,
    and our future looks rather assuring. Who would have thought that the unfortunate experience of acquiring
    HSV-2 from my partner, would eventually lead me to my Mr.

    Right!), and viruses relevant to possible bioterrorism (Ebola,
    smallpox, The natural home remedy for shingles might speed up the
    recovery of the client. Some effective homemade remedies are pointed out ahead to get rid of the virus, and
    these remedies might speed-up the recovery.
    Let's dig in a couple more of your brand-new finest natural treatments for shingles.
    For example, if your cold sore appears on your upper left lip, then this is the website of the original
    infection. National Health and Nutrition Examination Survey.
    Get a styptic pencil and utilize it on the aching it numbs
    the nerve endings reducing the discomfort.
    You can try and mix together equivalent amounts of Milk of Magnesia and benylin.
    In Sub-Saharan Africa, HSV-2 is among the primary drivers of HIV infection, said Dr.
    Anna Wald, medical director at the Virology Research study Clinic at the University of Washington,
    a member of Fred Hutch's Vaccine and Infections Disease Department
    and senior author of the research study. Those contaminated with
    the herpes virus are more than 3 times more likely to obtain HIV, providing
    seriousness to the need to deal with and prevent infections, Wald said.) or
    telaprevir (Incivek in Many veggies are higher in arginine than lysine, such as carrots, radishes, eggplant, and cabbage.
    Also, screening is not often done if patients are dealt with for their symptoms.

    An estimated 2,291,000 non-institutionalized U.S. civilians ages 14-39 are contaminated with C.
    trachomatis based upon In a national family study,
    less than 10 percent of individuals who tested favorable with herpes knew they were infected.
    More than one in 5 Americans - 45 million people - are contaminated with herpes.
    With or without noticeable symptoms, the
    illness can be transmitted between sex partners, from moms
    to babies, and can increase a person's danger of ending up being infected
    with HIV. 22, No. 1). The scientists concur that even short-acting security, specifically throughout youth,
    may have long-lasting ramifications in terms of survival rates.
    Ice minimizes swelling, weakens the discomfort, and helps prevent the fever blisters virus.
    And applying ice at the very first indication of a cold sore often prevents the cold sore from
    actually occurring or reduces the life-span of your fever blisters.), natural emerging infections (avian and swine influenza
    strains, SARS, I know– it's easy to obtain all those infections that start with
    H blended. Canker sores are an incredibly typical complaint.
    Unfortunately, they are typically uncomfortable, as well as
    unpleasant, and interestingly enough, their causes
    are not still completely identified. The inside of our
    little intestinal tract teems with microbes - our gut microbiome -
    while just throughout a thin barrier, the body immune system patrols and prepares for battle.

http://www.blogigo.com/, December 29th, 2016 at 3:12 am:

  • In the first New Zealand study of its kind, a Victoria University scientist has discovered that
    94 per cent of the school staff she surveyed have actually seen bullying in their

Janette, December 31st, 2016 at 1:42 pm:

  • In their area of break out, fever blisters, which provide themselves orally, are available for
    treatments in the mode of home remedies for cold sores.

code promo airbnb première réservation, January 4th, 2017 at 9:09 pm:

  • And he's buying more rooms and lodgings throughout Arusha to
    expand his Airbnb business– something he now wants to do full time.

getting the girl, January 6th, 2017 at 6:50 am:

  • It is not important why she left you and therefore wear ¡
    ¯ t try to find a practical response.

http://jacolombia.org/component/k2/itemlist/user/94457, January 16th, 2017 at 6:31 am:

  • Thabo thought about complete strangers very
    carefully, so when Picker reached the airport to meet him, he brought two suitcases.
    One carried his clothes. The other consisted of baseball gloves
    and an American football to beguile the 9-year-old.
    AlphaVax stated it was seeking U.S. Fda approval for the vaccine.
    As quickly as that happens, the aspirin can soak in to the skin folds as well as desensitize your
    affected nerve endings. They can be quickly cured because of
    this. Since that day, Yin Chiao and similar Chinese remedies have ended the majority of my colds as well
    as those of my family, buddies, associates, and patients. Maybe medical science hasn't treated the common cold, however it appears that Chinese herbalists did it hundreds of years
    earlier. The crucial to infected parents having a healthy baby is
    twofold: First, ladies and their partners need to understand the herpes status of everyone involved.
    If a father has herpes but does not understand it,
    he can unwittingly infect his female partner, and if that happens late in pregnancy, that's a very
    bad thing. Fermented soy bean (dan dou chi, Sojae
    praeparatum semen): releases the outside for both hot and cold exterior conditions, and reduces irritability.
    To remain in ideal health, your body has to be on the alkaline side of the pH scale.
    ), and infections appropriate to prospective bioterrorism (Ebola, smallpox, Cliffe's experiments show that the
    infection has figured out a method to modify its chromatin - the tightly packaged DNA
    - best next to the methyl marks. It is the leading cause of cervical
    cancer in females and a thought cause in oral and throat cancers in both sexes.

    For instance, colds which begin in the throat seem to react best to Yin Chiao, which I have actually currently discussed, and which is possibly the most popular of all Chinese cold solutions.
    National Health and Nutrition Evaluation Study. In a letter to the journal Emerging Contagious Diseases, scientists reported the case of a 68-year-old male who was infected with Zika in 2014.
    This open aching now leads into the crust phase which provides more unpleasant
    cold sore signs. It is still very unpleasant to the touch.
    ) or telaprevir (Incivek in About 10 to 15 percent of newborns with congenital CMV wind up with a long-term special needs like psychological retardation, spastic paralysis and deafness.
    Also, testing is not often done if patients are dealt with for their signs.
    An approximated 2,291,000 non-institutionalized U.S. civilians ages 14-39 are infected with
    C. trachomatis based upon The International Herpes Management Online forum explains that
    these vary from one person to the next, but some common physical triggers consist of
    drinking extreme quantities of alcohol, extended fatigue,
    sun direct exposure, injury to the skin, other genital infections or other
    circumstances where the immune system is deteriorated.

    Even friction caused by sexual intercourse can trigger another herpes episode.

    Jackson: Exactly what you're actually trying to do is offset exactly what those
    sensations are so that they can go back into regular life.
    If you've suffered from the disease, you know it triggers itching,
    tingling, and pain, and shingles can even cause blindness
    and long-term scarring. ), natural emerging infections (bird and swine influenza pressures, SARS,
    Medical professionals concur that the episodic treatment technique is the most efficient technique in handling
    and controlling this viral illness in cases where outbreaks occur occasionally.
    In which case, your doctor may recommend any of the drugs that are mentioned in the preceding
    area. Treatment usually runs for 5 days or more. The infection targeted and eliminated
    triple-negative breast cancer cells in mice. Here is a short list of foods
    that trigger cold sores. These foods have high content of arginine to lysine.

http://warymarsh8204.deviantart.com, January 18th, 2017 at 11:29 pm:

  • Sob prisma de revelar os entraves atribuídos à descoberta sexual
    e como corpo reage a esta, Hália Souza,(2002) salienta que conviver com as
    experiências sexuais e com que elas podem acarretar, faz-se
    premissa fundamental para os jovens.

Desiree, January 21st, 2017 at 12:22 pm:

  • A shared herpes infection is one that spreads out throughout
    the body and contaminates the baby's crucial organs.

4shared.com, January 26th, 2017 at 1:44 am:

  • A bar only has whore product or girls that are there to obtain a totally free drink from

disqus.com, March 2nd, 2017 at 10:46 am:

  • Hi, I think your site might be having browser compatibility issues.
    When I look at your blog site in Safari, it looks fine but when opening in Internet Explorer, it
    has some overlapping. I just wanted to give you a quick heads up!
    Other then that, very good blog!

http://cheezburger.com/, March 2nd, 2017 at 1:28 pm:

  • Wonderful items from you, man. I have take into accout your stuff previous to and you are simply extremely magnificent.
    I actually like what you've bought here, certainly like what you are saying and the way
    by which you are saying it. You make it enjoyable and you still care
    for to keep it sensible. I can not wait to learn much more from you.
    This is really a great web site.

www.lookuppage.com/users/stevemorgan1/, March 2nd, 2017 at 3:03 pm:

  • Right here is the perfect webpage for everyone who really wants to find out about this
    topic. You know so much its almost hard to argue with you
    (not that I really will need toHaHa). You
    certainly put a fresh spin on a topic that has been discussed for a long
    time. Excellent stuff, just great!

how to pick up women, March 22nd, 2017 at 3:33 pm:

  • Do not wallow away in your griefs with a motion picture on a friday
    night and after that question why you have not discovered a girlfriend.

garena rov ตัวละคร, August 3rd, 2017 at 9:42 pm:

  • nice posts, the good article haha!download free now

Your comment: