patternrubyrailsCritical
Rails 4: List of available datatypes
Viewed 0 times
listavailablerailsdatatypes
Problem
Where can I find a list of data types that can be used in Ruby on Rails 4?
Such as
I keep learning about new ones and I'd love to have a list I could easily refer to.
Such as
text
string
integer
float
date
I keep learning about new ones and I'd love to have a list I could easily refer to.
Solution
Here are all the Rails 4 (ActiveRecord migration) datatypes:
Source: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column
These are the same as with Rails 3.
If you use PostgreSQL, you can also take advantage of these:
They are stored as strings if you run your app with a not-PostgreSQL database.
More PostgreSQL data types
:binary
:boolean
:date
:datetime
:decimal
:float
:integer
:bigint
:primary_key
:references
:string
:text
:time
:timestamp
Source: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column
These are the same as with Rails 3.
If you use PostgreSQL, you can also take advantage of these:
:hstore
:json
:jsonb
:array
:cidr_address
:ip_address
:mac_address
They are stored as strings if you run your app with a not-PostgreSQL database.
More PostgreSQL data types
- Rails 4
- Rails 5
- Rails 6
- Rails 7
Context
Stack Overflow Q#17918117, score: 727
Revisions (0)
No revisions yet.