Stats

992 Contributors: 30 Sunday, August 6, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

ActiveRecord Migrations

Parameters

Column typeDescription
:primary_keyPrimary key
:stringShorter string datatype. Allows limit option for maximum number of characters.
:textLonger amount of text. Allows limit option for maximum number of bytes.
:integerInteger. Allows limit option for maximum number of bytes.
:bigintLarger integer
:floatFloat
:decimalDecimal number with variable precision. Allows precision and scale options.
:numericAllows precision and scale options.
:datetimeDateTime object for dates/times.
:timeTime object for times.
:dateDate object for dates.
:binaryBinary data. Allows limit option for maximum number of bytes.
:booleanBoolean

Remarks

  • Most migration files live in db/migrate/ directory. They’re identified by a UTC timestamp at the beginning of their file name: YYYYMMDDHHMMSS_create_products.rb.

  • The rails generate command can be shortened to rails g.

  • If a :type is not passed to a field, it defaults to a string.

Related Examples