Search code examples
ruby-on-railsrails-migrations

Where is the documentation page for ActiveRecord data types?


I can't find the active record documenation page that has a list of all the data types.

Can someone help me out?


Solution

  • If you're talking about the types for migrations, e.g. string, integer, datetime, etc, then you want ActiveRecord::ConnectionAdapters::TableDefinition, the column method. (Rails 5 edit: see also connection.add_column.)

    As of this update, the standard types are:

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

    The implementation of :decimal is different with each database, so I'd avoid it if possible. You may use a type not in this list as long as it is supported by your database (for example, :polygon in MySQL), but this will not be database agnostic and should also be avoided.