Rails 4: List of available datatypes


Where can I find a list of data types that can be used in Ruby on Rails 4? 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.

2/24/2016 8:48:19 AM

Accepted Answer

Here are all the Rails 4 (ActiveRecord migration) datatypes:

  • :binary
  • :boolean
  • :date
  • :datetime
  • :decimal
  • :float
  • :integer
  • :bigint
  • :primary_key
  • :references
  • :string
  • :text
  • :time
  • :timestamp

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.

Edit, 2016-Sep-19:

There's a lot more postgres specific datatypes in Rails 4 and even more in Rails 5.

5/23/2017 12:34:50 PM

It is important to know not only the types but the mapping of these types to the database types, too:

enter image description here

enter image description here

Source added - Agile Web Development with Rails 4


You can access this list everytime you want (even if you don't have Internet access) through:

rails generate model -h

Rails4 has some added datatypes for Postgres.

For example, railscast #400 names two of them:

Rails 4 has support for native datatypes in Postgres and we’ll show two of these here, although a lot more are supported: array and hstore. We can store arrays in a string-type column and specify the type for hstore.

Besides, you can also use cidr, inet and macaddr. For more information: