Where can I find a list of data types that can be used in rails 3? (such as text, string, integer, float, date, etc.?) I keep randomly learning about new ones, but I'd love to have a list I could easily refer to.
Asked
Active
Viewed 7.2k times
4 Answers
270
Here are all the Rails3
(ActiveRecord migration) datatypes:
:binary
:boolean
:date
:datetime
:decimal
:float
:integer
:primary_key
:references
:string
:text
:time
:timestamp

Xcodian Solangi
- 2,342
- 5
- 24
- 52

Nicolas Raoul
- 58,567
- 58
- 222
- 373
-
4and :references for polymorphic associations. See: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html – Ethan Jan 25 '12 at 08:46
-
1the guide has changed. Maybe a link to the relevant documentation should replace it. – Harry Moreno Jul 17 '13 at 21:21
-
1@HarryMoreno: Thanks for the tip! I updated the reference, please let me know if you find any better one. – Nicolas Raoul Jul 18 '13 at 03:41
-
References is not limited to polymorphic associations. And i would not count it as a datatype. – Pascal Aug 27 '13 at 13:24
67
It is important to know not only the types but the mapping of these types to the database types, too:
For, example, note that in MS SQL Server we are using:
- the old "datetime" instead "datetime2"
- decimal with its default precision
- text and varchar instead nvarchar
- int (not possible to use tiny int/small int/big int)
- image instead BLOB

gotqn
- 42,737
- 46
- 157
- 243
-
2As find from [this blog](http://ariejan.net/2009/08/20/once-and-for-all-rails-migrations-integer-limit-option/). The tinyint/smallint/bigint can be set by using :limit option with :integer. I have tested it on Rails 3 and MySQL, they are still working, just as said in the blog, they are signed integer. – RacsO Dec 18 '13 at 03:23
26
Do you mean for defining active record migrations? or do you mean Ruby data types?
Here's a link that may help for creating migrations:

Bill the Lizard
- 398,270
- 210
- 566
- 880

Tim Stephenson
- 830
- 1
- 7
- 15
15
It might be helpful to know generally what these data types are used for:
- binary - is for storing data such as images, audio, or movies.
- boolean - is for storing true or false values.
- date - store only the date
- datetime - store the date and time into a column.
- decimal - is for decimals.
- float - is for decimals. (What's the difference between decimal and float?)
- integer - is for whole numbers.
- primary_key - unique key that can uniquely identify each row in a table
- string - is for small data types such as a title. (Should you choose string or text?)
- text - is for longer pieces of textual data, such as a paragraph of information.
- time - is for time only
- timestamp - for storing date and time into a column.
I hope that helps someone! Also, here's the official list: http://guides.rubyonrails.org/migrations.html#supported-types